void MP3EncoderBladeEnc::initEncoder() { BE_CONFIG config; memset(&config, 0, sizeof(config)); config.dwConfig = BE_CONFIG_LAME; config.format.LHV1.dwStructVersion = 1; config.format.LHV1.dwStructSize = sizeof(config); config.format.LHV1.dwSampleRate = 44100; config.format.LHV1.nMode = BE_MP3_MODE_JSTEREO; config.format.LHV1.nPreset = LQP_STANDARD; config.format.LHV1.nVbrMethod = VBR_METHOD_DEFAULT; config.format.LHV1.bWriteVBRHeader = true; config.format.LHV1.bEnableVBR = true; BE_ERR err = beInitStream(&config, &m_writeSamples, &m_minOutputSize, &m_handle); if (err != BE_ERR_SUCCESSFUL) throwf("MP3EncoderBladeEnc: couldn't open stream (%s)", error(err).c_str()); m_writeBytes = (BufferFormat::Local.bytesPerSample() * m_writeSamples); m_writtenBytes = 0; m_bufferLeft = new char[m_writeBytes / 2]; m_bufferRight = new char[m_writeBytes / 2]; m_bufferOutput = new char[m_minOutputSize]; m_writeLeft = BufferFormat::Local.buf(m_bufferLeft); m_writeRight = BufferFormat::Local.buf(m_bufferRight); }
lame_stream * lame_wrapper::init_stream( unsigned long input_samplerate, unsigned short output_bitrate, unsigned short channels) { BE_CONFIG beConfig ={0,}; HBE_STREAM stream_handle; memset(&beConfig,0,sizeof(beConfig)); // clear all fields // use the LAME config structure beConfig.dwConfig = BE_CONFIG_LAME; // this are the default settings for testcase.wav beConfig.format.LHV1.dwStructVersion = 1; beConfig.format.LHV1.dwStructSize = sizeof(beConfig); beConfig.format.LHV1.dwSampleRate = input_samplerate; // INPUT FREQUENCY beConfig.format.LHV1.dwReSampleRate = 0; // DON"T RESAMPLE if (channels == 2) { beConfig.format.LHV1.nMode = BE_MP3_MODE_JSTEREO; // OUTPUT IN STREO } // if (channels == 2) else if (channels ==1) { beConfig.format.LHV1.nMode = BE_MP3_MODE_MONO; } else { throw std::runtime_error( "mp3 output should be 1- or 2-channel"); } beConfig.format.LHV1.dwBitrate = output_bitrate; // MINIMUM BIT RATE beConfig.format.LHV1.nPreset = LQP_R3MIX; // QUALITY PRESET SETTING beConfig.format.LHV1.dwMpegVersion = MPEG1; // MPEG VERSION (I or II) beConfig.format.LHV1.dwPsyModel = 0; // USE DEFAULT PSYCHOACOUSTIC MODEL beConfig.format.LHV1.dwEmphasis = 0; // NO EMPHASIS TURNED ON beConfig.format.LHV1.bOriginal = TRUE; // SET ORIGINAL FLAG beConfig.format.LHV1.bWriteVBRHeader = TRUE; // Write INFO tag beConfig.format.LHV1.bNoRes = TRUE; // No Bit resorvoir // Init the MP3 Stream err = beInitStream(&beConfig, &dwSamples, &dwMP3Buffer, &hbeStream); return NULL; }