Всем доброго времени суток.
Столкнулся с проблемой: звук проигрывается только 1 секунду.
Подозреваю, что буфер не полностью заполняется. Листинги приведены ниже.
Всем спасибо за помощь!
Считывание данных:
SoundOGGFile* audioData = reinterpret_cast< SoundOGGFile* >(FileHandle ); le::UInt32_t length = Size1 * Size2; if ( audioData->sizeConsumed + length > audioData->size ) length = audioData->size - audioData->sizeConsumed; char* moreData = new char[ length ]; audioData->file.clear( ); audioData->file.seekg( audioData->sizeConsumed ); if ( !audioData->file.read( &moreData[0], length ) ) { if ( audioData->file.eof( ) ) { audioData->file.clear( ); // just clear the error, we will resolve it later } else if ( audioData->file.fail( ) ) { le::g_consoleSystem->PrintError( "OGG stream has fail bit set " ); audioData->file.clear( ); return 0; } else if ( audioData->file.bad( ) ) { le::g_consoleSystem->PrintError( "OGG file is bad" ); audioData->file.clear( ); return 0; } } audioData->sizeConsumed += length; memcpy( Destination, &moreData[0], length ); delete[] moreData; audioData->file.clear( ); return length; }
Заполнение буфера:
SoundOGGFile audioData; le::g_consoleSystem->PrintInfo("Path %s", Path); audioData.file.open( Path, std::ios::binary); if ( !audioData.file.is_open( )) { le::g_consoleSystem->PrintError( "Don`t open the ogg file"); return nullptr; } // Registered ogg_callbacks ov_callbacks oggCallbacks; oggCallbacks.read_func = read_ogg_callback; oggCallbacks.close_func = nullptr; oggCallbacks.seek_func = nullptr; oggCallbacks.tell_func = nullptr; le::g_consoleSystem->PrintInfo( "CALLBACKS OK"); // Take the data size audioData.file.seekg( 0, std::ios_base::beg); audioData.file.ignore( std::numeric_limits<std::streamsize>::max( )); audioData.size = audioData.file.gcount( ); audioData.file.clear( ); audioData.file.seekg( 0, std::ios_base::beg); le::g_consoleSystem->PrintInfo( "DATA SIZE"); if ( ov_open_callbacks( reinterpret_cast<void*>( &audioData), &audioData.oggVorbisFile, nullptr, -1, oggCallbacks) < 0) { le::g_consoleSystem->PrintError( "Could not ov_open_callbacks"); return nullptr; } le::g_consoleSystem->PrintInfo( "OPEN_CALLBACK OK"); vorbis_info* vorbisInfo = ov_info( &audioData.oggVorbisFile, -1); audioData.channels = vorbisInfo->channels; audioData.sampleRate = vorbisInfo->rate; audioData.bitsPerSample = 16; ogg_int64_t bufferSize = 65536; char* data = new char[bufferSize]; std::int32_t dataSoFar = 0; while ( dataSoFar < bufferSize) { std::int32_t result = ov_read( &audioData.oggVorbisFile, &data[dataSoFar], bufferSize - dataSoFar, 0, 2, 1, ( int*)&audioData.oggCurrentSection); le::g_consoleSystem->PrintInfo( "WHILE"); if ( result == OV_HOLE) { le::g_consoleSystem->PrintError( "OV_HOLE found in initial read of buffer"); break; } else if ( result == OV_EBADLINK) { le::g_consoleSystem->PrintError( "OV_EBADLINK found in initial read of buffer"); break; } else if ( result == OV_EINVAL) { le::g_consoleSystem->PrintError( "OV_EINVAL found in initial read of buffer"); break; } else if ( result == 0) { le::g_consoleSystem->PrintError( "EOF found in initial read of buffer"); break; } dataSoFar += result; } le::ISoundBuffer* soundBuffer = ( le::ISoundBuffer*)AudioSystemFactory->Create( SOUNDBUFFER_INTERFACE_VERSION); soundBuffer->Create( ); soundBuffer->Append( data, bufferSize/audioData.channels, audioData.channels, audioData.sampleRate); //тут информация передается музыке delete[] data; return soundBuffer;
Тема в архиве.
Тема закрыта.