void FOpusAudioInfo::ExpandFile(uint8* DstBuffer, struct FSoundQualityInfo* QualityInfo) { check(OpusDecoderWrapper); check(DstBuffer); check(QualityInfo); check(QualityInfo->SampleDataSize <= SrcBufferDataSize); // Ensure we're at the start of the audio data SrcBufferOffset = AudioDataOffset; uint32 RawPCMOffset = 0; while (RawPCMOffset < QualityInfo->SampleDataSize) { uint16 FrameSize = 0; Read(&FrameSize, sizeof(uint16)); int32 DecodedSamples = DecompressToPCMBuffer(FrameSize); if (DecodedSamples < 0) { RawPCMOffset += ZeroBuffer(DstBuffer + RawPCMOffset, QualityInfo->SampleDataSize - RawPCMOffset); } else { LastPCMByteSize = IncrementCurrentSampleCount(DecodedSamples) * SampleStride; RawPCMOffset += WriteFromDecodedPCM(DstBuffer + RawPCMOffset, QualityInfo->SampleDataSize - RawPCMOffset); } } }
void CVWString::SetBufferSize( int str_length ) { Reset(); v_nSize = str_length + 1; v_pData = (wchar*)alloc(v_nSize * SIZEOFWCHAR); ZeroBuffer(); }
void ProcessVector(float *input) { //Add the FFT to the total for (unsigned int i = 0; i < m_vector_length; i++){ m_buffer[i] += input[i]; } m_count++; //increment the total if (m_avg_size == m_count){ //we've averaged over the number we intended to double freqs[m_vector_length]; //for convenience float bands0[m_vector_length]; //bands in order of frequency float bands1[m_vector_length]; //fine window bands float bands2[m_vector_length]; //coarse window bands Rearrange(bands0, freqs, m_centre_freq_1, m_bandwidth0); //organise the buffer into a convenient order (saves to bands0) GetBands(bands0, bands1, m_bandwidth1); //apply the fine window (saves to bands1) GetBands(bands0, bands2, m_bandwidth2); //apply the coarse window (saves to bands2) PrintSignals(freqs, bands1, bands2); m_count = 0; //next time, we're starting from scratch - so note this ZeroBuffer(); //get ready to start again m_wait_count++; //we've just done another listen if (m_time/(m_bandwidth0/(double)(m_vector_length * m_avg_size)) <= m_wait_count){ //if we should move to the next frequency while (true) { //keep moving to the next frequency until we get to one we can listen on (copes with holes in the tunable range) if (m_centre_freq_2 <= m_centre_freq_1){ //we reached the end! //do something to end the scan fprintf(stderr, "[*] Finished scanning\n"); //say we're exiting exit(0); //TODO: This probably isn't the right thing, but it'll do for now } m_centre_freq_1 += m_step; //calculate the frequency we should change to double actual = m_source->set_center_freq(m_centre_freq_1); //change frequency if ((m_centre_freq_1 - actual < 10.0) && (actual - m_centre_freq_1 < 10.0)){ //success break; //so stop changing frequency } } m_wait_count = 0; //new frequency - we've listenned 0 times on it } } }
//----------------------------------------------------------------------------- // 描述: 数据包首部初始化 // 参数: // nSeqNumberA - 为0时表示自动增长,否则直接赋值 //----------------------------------------------------------------------------- void CUdpPacketHeader::Init(uint nActionCodeA, uint nSeqNumberA,uint nOrderA) { ZeroBuffer(this, sizeof(CUdpPacketHeader)); nProtoType = PP_UDP; //包的协议 nActionCode = nActionCodeA; //包的动作代码 //包的序列号 if (nSeqNumberA == 0) nSeqNumber = Tracker.GetAllocator().AllocId() + 1; else nSeqNumber = nSeqNumberA; nOrder = nOrderA; nUserIp = StringToIp(GetLocalIp()); //用户IP wUdpPort = TrackerServer.GetLocalPort(); //UDP端口 wTcpPort = PeerTcpServer.GetLocalPort(); //TCP端口 char * UserName = Tracker.GetstrUserName(); char * UserPassword = Tracker.GetstrUserPassword(); strcpy(strUserName,UserName); strcpy(strUserPassword,UserPassword); UpdateCheckSum(); }
scanner_sink(osmosdr::source::sptr source, unsigned int vector_length, double centre_freq_1, double centre_freq_2, double bandwidth0, double bandwidth1, double bandwidth2, double step, unsigned int avg_size, double spread, double threshold, double ptime) : gr::block ("scanner_sink", gr::io_signature::make (1, 1, sizeof (float) * vector_length), gr::io_signature::make (0, 0, 0)), m_source(source), //We need the source in order to be able to control it m_buffer(new float[vector_length]), //buffer into which we accumulate the total for averaging m_vector_length(vector_length), //size of the FFT m_count(0), //number of FFTs totalled in the buffer m_wait_count(0), //number of times we've listenned on this frequency m_avg_size(avg_size), //the number of FFTs we should average over m_step(step), //the amount by which the frequency shold be incremented m_centre_freq_1(centre_freq_1), //start frequency (and then current frequency) m_centre_freq_2(centre_freq_2), //end frequency m_bandwidth0(bandwidth0), //samples per second m_bandwidth1(bandwidth1), //fine window (band)width m_bandwidth2(bandwidth2), //coarse window (band)width m_threshold(threshold), //threshold in dB for discovery m_spread(spread), //minumum distance between radio signals (overlapping scans might produce slightly different frequencies) m_time(ptime), //the amount of time to listen on the same frequency for m_start_time(time(0)) //the start time of the scan (useful for logging/reporting/monitoring) { ZeroBuffer(); }
FileSystemCode_t FsWriteToFile( _In_ FileSystemDescriptor_t* FileSystem, _In_ MfsEntryHandle_t* Handle, _In_ DmaBuffer_t* BufferObject, _In_ size_t Length, _Out_ size_t* BytesWritten) { MfsInstance_t* Mfs = (MfsInstance_t*)FileSystem->ExtensionData; MfsEntry_t* Entry = (MfsEntry_t*)Handle->Base.Entry; FileSystemCode_t Result = FsOk; uint64_t Position = Handle->Base.Position; size_t BucketSizeBytes = Mfs->SectorsPerBucket * FileSystem->Disk.Descriptor.SectorSize; size_t BytesToWrite = Length; TRACE("FsWriteEntry(Id 0x%x, Position %u, Length %u)", Handle->Base.Id, LODWORD(Position), Length); *BytesWritten = 0; Result = MfsEnsureRecordSpace(FileSystem, Entry, Position + BytesToWrite); if (Result != FsOk) { return Result; } // Guard against newly allocated files if (Handle->DataBucketPosition == MFS_ENDOFCHAIN) { Handle->DataBucketPosition = Entry->StartBucket; Handle->DataBucketLength = Entry->StartLength; Handle->BucketByteBoundary = 0; } // Write in a loop to make sure we write all requested bytes while (BytesToWrite) { // Calculate which bucket, then the sector offset // Then calculate how many sectors of the bucket we need to read uint64_t Sector = MFS_GETSECTOR(Mfs, Handle->DataBucketPosition); uint64_t SectorOffset = (Position - Handle->BucketByteBoundary) % FileSystem->Disk.Descriptor.SectorSize; size_t SectorIndex = (size_t)((Position - Handle->BucketByteBoundary) / FileSystem->Disk.Descriptor.SectorSize); size_t SectorsLeft = MFS_GETSECTOR(Mfs, Handle->DataBucketLength) - SectorIndex; size_t SectorCount = 0, ByteCount = 0; // Ok - so sectorindex contains the index in the bucket // and sector offset contains the byte-offset in that sector // Calculate the sector index into bucket Sector += SectorIndex; // Calculate how many sectors we should read in SectorCount = DIVUP(BytesToWrite, FileSystem->Disk.Descriptor.SectorSize); // Do we cross a boundary? if (SectorOffset + BytesToWrite > FileSystem->Disk.Descriptor.SectorSize) { SectorCount++; } // Adjust for bucket boundary SectorCount = MIN(SectorsLeft, SectorCount); // Adjust for number of bytes read ByteCount = (size_t)MIN(BytesToWrite, (SectorCount * FileSystem->Disk.Descriptor.SectorSize) - SectorOffset); // Ex pos 490 - length 50 // SectorIndex = 0, SectorOffset = 490, SectorCount = 2 - ByteCount = 50 (Capacity 4096) // Ex pos 1109 - length 450 // SectorIndex = 2, SectorOffset = 85, SectorCount = 2 - ByteCount = 450 (Capacity 4096) // Ex pos 490 - length 4000 // SectorIndex = 0, SectorOffset = 490, SectorCount = 8 - ByteCount = 3606 (Capacity 4096) TRACE("Write metrics - Sector %u + %u, Count %u, ByteOffset %u, ByteCount %u", LODWORD(Sector), SectorIndex, SectorCount, LODWORD(SectorOffset), ByteCount); // First of all, calculate the bounds as we might need to read // in existing data - Start out by clearing our combination buffer ZeroBuffer(Mfs->TransferBuffer); // Case 1 - Handle padding if (SectorOffset != 0 || ByteCount != FileSystem->Disk.Descriptor.SectorSize) { // Start building the sector if (MfsReadSectors(FileSystem, Mfs->TransferBuffer, Sector, SectorCount, &SectorCount) != OsSuccess) { ERROR("Failed to read sector %u for combination step", LODWORD(Sector)); Result = FsDiskError; break; } // Adjust the bytecount if we are not able to read all in one go if ((FileSystem->Disk.Descriptor.SectorSize * SectorCount) < ByteCount) { ByteCount = FileSystem->Disk.Descriptor.SectorSize * SectorCount; } } // Now write the data to the sector SeekBuffer(Mfs->TransferBuffer, (size_t)SectorOffset); CombineBuffer(Mfs->TransferBuffer, BufferObject, ByteCount, NULL); // Perform the write (Raw - as we need to pass the datapointer) if (MfsWriteSectors(FileSystem, Mfs->TransferBuffer, Sector, SectorCount, &SectorCount) != OsSuccess) { ERROR("Failed to write sector %u", LODWORD(Sector)); Result = FsDiskError; break; } // Increase the pointers and decrease with bytes read // Adjust the bytecount if we are not able to read all in one go if ((FileSystem->Disk.Descriptor.SectorSize * SectorCount) < ByteCount) { ByteCount = FileSystem->Disk.Descriptor.SectorSize * SectorCount; } Position += ByteCount; *BytesWritten += ByteCount; BytesToWrite -= ByteCount; // Do we need to switch bucket? // We do if the position we have read to equals end of bucket if (Position == (Handle->BucketByteBoundary + (Handle->DataBucketLength * BucketSizeBytes))) { MapRecord_t Link; // We have to lookup the link for current bucket if (MfsGetBucketLink(FileSystem, Handle->DataBucketPosition, &Link) != OsSuccess) { ERROR("Failed to get link for bucket %u", Handle->DataBucketPosition); Result = FsDiskError; break; } // Check for EOL if (Link.Link == MFS_ENDOFCHAIN) { break; } Handle->DataBucketPosition = Link.Link; // Lookup length of link if (MfsGetBucketLink(FileSystem, Handle->DataBucketPosition, &Link) != OsSuccess) { ERROR("Failed to get length for bucket %u", Handle->DataBucketPosition); Result = FsDiskError; break; } Handle->DataBucketLength = Link.Length; Handle->BucketByteBoundary += (Link.Length * BucketSizeBytes); } } // entry->modified = now Entry->ActionOnClose = MFS_ACTION_UPDATE; return Result; }
bool FOpusAudioInfo::StreamCompressedData(uint8* Destination, bool bLooping, uint32 BufferSize) { check(OpusDecoderWrapper); check(Destination); SCOPE_CYCLE_COUNTER(STAT_OpusDecompressTime); UE_LOG(LogAudio, Log, TEXT("Streaming compressed data from SoundWave'%s' - Chunk %d, Offset %d"), *StreamingSoundWave->GetName(), CurrentChunkIndex, SrcBufferOffset); // Write out any PCM data that was decoded during the last request uint32 RawPCMOffset = WriteFromDecodedPCM(Destination, BufferSize); // If next chunk wasn't loaded when last one finished reading, try to get it again now if (SrcBufferData == NULL) { SrcBufferData = IStreamingManager::Get().GetAudioStreamingManager().GetLoadedChunk(StreamingSoundWave, CurrentChunkIndex); if (SrcBufferData) { SrcBufferDataSize = StreamingSoundWave->RunningPlatformData->Chunks[CurrentChunkIndex].DataSize; SrcBufferOffset = CurrentChunkIndex == 0 ? AudioDataOffset : 0; } else { // Still not loaded, zero remainder of current buffer UE_LOG(LogAudio, Warning, TEXT("Unable to read from chunk %d of SoundWave'%s'"), CurrentChunkIndex, *StreamingSoundWave->GetName()); ZeroBuffer(Destination + RawPCMOffset, BufferSize - RawPCMOffset); return false; } } bool bLooped = false; if (bStoringEndOfFile && LastPCMByteSize > 0) { // delayed returning looped because we hadn't read the entire buffer bLooped = true; bStoringEndOfFile = false; } while (RawPCMOffset < BufferSize) { uint16 FrameSize = 0; Read(&FrameSize, sizeof(uint16)); int32 DecodedSamples = DecompressToPCMBuffer(FrameSize); if (DecodedSamples < 0) { LastPCMByteSize = 0; ZeroBuffer(Destination + RawPCMOffset, BufferSize - RawPCMOffset); return false; } else { LastPCMByteSize = IncrementCurrentSampleCount(DecodedSamples) * SampleStride; RawPCMOffset += WriteFromDecodedPCM(Destination + RawPCMOffset, BufferSize - RawPCMOffset); // Have we reached the end of buffer if (SrcBufferOffset >= SrcBufferDataSize) { // Special case for the last chunk of audio if (CurrentChunkIndex == StreamingSoundWave->RunningPlatformData->NumChunks - 1) { // check whether all decoded PCM was written if (LastPCMByteSize == 0) { bLooped = true; } else { bStoringEndOfFile = true; } if (bLooping) { CurrentChunkIndex = 0; SrcBufferOffset = AudioDataOffset; CurrentSampleCount = 0; } else { RawPCMOffset += ZeroBuffer(Destination + RawPCMOffset, BufferSize - RawPCMOffset); } } else { CurrentChunkIndex++; SrcBufferOffset = 0; } SrcBufferData = IStreamingManager::Get().GetAudioStreamingManager().GetLoadedChunk(StreamingSoundWave, CurrentChunkIndex); if (SrcBufferData) { UE_LOG(LogAudio, Log, TEXT("Incremented current chunk from SoundWave'%s' - Chunk %d, Offset %d"), *StreamingSoundWave->GetName(), CurrentChunkIndex, SrcBufferOffset); SrcBufferDataSize = StreamingSoundWave->RunningPlatformData->Chunks[CurrentChunkIndex].DataSize; } else { SrcBufferDataSize = 0; RawPCMOffset += ZeroBuffer(Destination + RawPCMOffset, BufferSize - RawPCMOffset); } } } } return bLooped; }
bool FOpusAudioInfo::ReadCompressedData(uint8* Destination, bool bLooping, uint32 BufferSize /*= 0*/) { check(OpusDecoderWrapper); check(Destination); SCOPE_CYCLE_COUNTER(STAT_OpusDecompressTime); // Write out any PCM data that was decoded during the last request uint32 RawPCMOffset = WriteFromDecodedPCM(Destination, BufferSize); bool bLooped = false; if (bStoringEndOfFile && LastPCMByteSize > 0) { // delayed returning looped because we hadn't read the entire buffer bLooped = true; bStoringEndOfFile = false; } while (RawPCMOffset < BufferSize) { uint16 FrameSize = 0; Read(&FrameSize, sizeof(uint16)); int32 DecodedSamples = DecompressToPCMBuffer(FrameSize); if (DecodedSamples < 0) { LastPCMByteSize = 0; ZeroBuffer(Destination + RawPCMOffset, BufferSize - RawPCMOffset); return false; } else { LastPCMByteSize = IncrementCurrentSampleCount(DecodedSamples) * SampleStride; RawPCMOffset += WriteFromDecodedPCM(Destination + RawPCMOffset, BufferSize - RawPCMOffset); if (SrcBufferOffset >= SrcBufferDataSize) { // check whether all decoded PCM was written if (LastPCMByteSize == 0) { bLooped = true; } else { bStoringEndOfFile = true; } if (bLooping) { SrcBufferOffset = AudioDataOffset; CurrentSampleCount = 0; } else { RawPCMOffset += ZeroBuffer(Destination + RawPCMOffset, BufferSize - RawPCMOffset); } } } } return bLooped; }