void ModMp3::run() { SDL_AudioSpec desired, obtained, hardwareSpec; // setting the audio format desired.freq = 22050; desired.format = AUDIO_S16; desired.channels = 2; desired.samples = 1024; desired.callback = playBuffer; desired.userdata = NULL; SDL_Init(SDL_INIT_AUDIO); SDL_OpenAudio(&desired, &obtained); hardwareSpec = obtained; // Initialize madxlib madx_init(out_buffer, &mxhouse); // open the files in_file = fopen( m_fileToPlay.toAscii().data(), "rb"); out_file = fopen("/test.pcm", "wb"); SDL_PauseAudio( 0 ); while ( (false == m_haveToStop) && (SDL_GetAudioStatus() == SDL_AUDIO_PLAYING) ) SDL_Delay(1000); // clean-up madx_deinit( &mxhouse ); fclose( in_file ); fclose( out_file ); SDL_CloseAudio(); SDL_Quit(); }
MP3Codec::MP3Codec() { m_SampleRate = 0; m_Channels = 0; m_BitsPerSample = 0; m_TotalTime = 0; m_Bitrate = 0; m_CodecName = "mp3"; // mp3 related m_CallAgainWithSameBuffer = false; m_readRetries = 5; m_lastByteOffset = 0; m_InputBufferSize = 64*1024; // 64k is a reasonable amount, considering that we actual are // using a background reader thread now that caches in advance. m_InputBuffer = new BYTE[m_InputBufferSize]; m_InputBufferPos = 0; memset(&m_Formatdata,0,sizeof(m_Formatdata)); m_DataFormat = AE_FMT_FLOAT; // create our output buffer m_OutputBufferSize = OUTPUTFRAMESIZE * 4; // enough for 4 frames m_OutputBuffer = new BYTE[m_OutputBufferSize]; m_OutputBufferPos = 0; m_Decoding = false; m_IgnoreFirst = true; // we want to be gapless m_IgnoredBytes = 0; m_IgnoreLast = true; m_eof = false; // VBR stuff m_iSeekOffsets = 0; m_fTotalDuration = 0.0f; m_SeekOffset = NULL; m_iFirstSample = 0; m_iLastSample = 0; memset(&mxhouse, 0, sizeof(madx_house)); memset(&mxstat, 0, sizeof(madx_stat)); mxsig = ERROR_OCCURED; m_HaveData = false; flushcnt = 0; if (m_dll.Load()) madx_init(&mxhouse); }