void projectM::projectM_init ( int gx, int gy, int fps, int texsize, int width, int height ) { setlocale(LC_NUMERIC, "C"); /** Initialise start time */ timeKeeper = new TimeKeeper(_settings.presetDuration,_settings.smoothPresetDuration, _settings.easterEgg); /** Nullify frame stash */ /** Initialise per-pixel matrix calculations */ /** We need to initialise this before the builtin param db otherwise bass/mid etc won't bind correctly */ assert ( !beatDetect ); if (!_pcm) _pcm = new PCM(); assert(pcm()); beatDetect = new BeatDetect ( _pcm ); if ( _settings.fps > 0 ) mspf= ( int ) ( 1000.0/ ( float ) _settings.fps ); else mspf = 0; this->renderer = new Renderer ( width, height, gx, gy, texsize, beatDetect, settings().presetURL, settings().titleFontURL, settings().menuFontURL ); running = true; initPresetTools(gx, gy); #ifdef USE_THREADS pthread_mutex_init(&mutex, NULL); #ifdef SYNC_PRESET_SWITCHES pthread_mutex_init(&preset_mutex, NULL); #endif pthread_cond_init(&condition, NULL); if (pthread_create(&thread, NULL, thread_callback, this) != 0) { std::cerr << "[projectM] failed to allocate a thread! try building with option USE_THREADS turned off" << std::endl;; exit(EXIT_FAILURE); } pthread_mutex_lock( &mutex ); #endif /// @bug order of operatoins here is busted //renderer->setPresetName ( m_activePreset->name() ); timeKeeper->StartPreset(); assert(pcm()); pipelineContext().fps = fps; pipelineContext2().fps = fps; }
bool StreamTrack::stream(ALuint buffer) { BOOST_ASSERT(m_audioEngine->getSettings().stream_buffer_size >= m_sfInfo.channels - 1); #ifdef AUDIO_OPENAL_FLOAT std::vector<ALfloat> pcm(m_audioEngine->getSettings().stream_buffer_size); #else std::vector<ALshort> pcm(m_audioEngine->getSettings().stream_buffer_size); #endif size_t size = 0; // SBS - C + 1 is important to avoid endless loops if the buffer size isn't a multiple of the channels while(size < pcm.size() - m_sfInfo.channels + 1) { // we need to read a multiple of sf_info.channels here const size_t samplesToRead = (m_audioEngine->getSettings().stream_buffer_size - size) / m_sfInfo.channels * m_sfInfo.channels; #ifdef AUDIO_OPENAL_FLOAT const sf_count_t samplesRead = sf_read_float(m_sndFile, pcm.data() + size, samplesToRead); #else const sf_count_t samplesRead = sf_read_short(m_sndFile, pcm.data() + size, samplesToRead); #endif if(samplesRead > 0) { BOOST_ASSERT(static_cast<std::make_unsigned<sf_count_t>::type>(samplesRead) <= std::numeric_limits<size_t>::max()); size += static_cast<size_t>(samplesRead); continue; } int error = sf_error(m_sndFile); if(error != SF_ERR_NO_ERROR) { logSndfileError(error); return false; } if(m_streamType == StreamType::Background) { sf_seek(m_sndFile, 0, SEEK_SET); } else { break; // Stream is ending - do nothing. } } if(size == 0) return false; alBufferData(buffer, m_format, pcm.data(), static_cast<ALsizei>(size * sizeof(pcm[0])), m_rate); DEBUG_CHECK_AL_ERROR(); return true; }
int init_smt(struct s_smc *smc, u_char *mac_addr) { int p ; #if defined(DEBUG) && !defined(DEBUG_BRD) debug.d_smt = 0 ; debug.d_smtf = 0 ; debug.d_rmt = 0 ; debug.d_ecm = 0 ; debug.d_pcm = 0 ; debug.d_cfm = 0 ; debug.d_plc = 0 ; #ifdef ESS debug.d_ess = 0 ; #endif #ifdef SBA debug.d_sba = 0 ; #endif #endif for ( p = 0; p < NUMPHYS; p ++ ) { smc->y[p].mib = & smc->mib.p[p] ; } set_oem_spec_val(smc) ; (void) smt_set_mac_opvalues(smc) ; init_fddi_driver(smc,mac_addr) ; smt_fixup_mib(smc) ; ev_init(smc) ; #ifndef SLIM_SMT smt_init_evc(smc) ; #endif smt_timer_init(smc) ; smt_agent_init(smc) ; pcm_init(smc) ; ecm_init(smc) ; cfm_init(smc) ; rmt_init(smc) ; for (p = 0 ; p < NUMPHYS ; p++) { pcm(smc,p,0) ; } ecm(smc,0) ; cfm(smc,0) ; rmt(smc,0) ; smt_agent_task(smc) ; PNMI_INIT(smc) ; return(0) ; }
/* * Init SMT */ int init_smt(struct s_smc *smc, u_char *mac_addr) /* u_char *mac_addr; canonical address or NULL */ { int p ; #if defined(DEBUG) && !defined(DEBUG_BRD) debug.d_smt = 0 ; debug.d_smtf = 0 ; debug.d_rmt = 0 ; debug.d_ecm = 0 ; debug.d_pcm = 0 ; debug.d_cfm = 0 ; debug.d_plc = 0 ; #ifdef ESS debug.d_ess = 0 ; #endif #ifdef SBA debug.d_sba = 0 ; #endif #endif /* DEBUG && !DEBUG_BRD */ /* First initialize the ports mib->pointers */ for ( p = 0; p < NUMPHYS; p ++ ) { smc->y[p].mib = & smc->mib.p[p] ; } set_oem_spec_val(smc) ; (void) smt_set_mac_opvalues(smc) ; init_fddi_driver(smc,mac_addr) ; /* HW driver */ smt_fixup_mib(smc) ; /* update values that depend on s.sas */ ev_init(smc) ; /* event queue */ #ifndef SLIM_SMT smt_init_evc(smc) ; /* evcs in MIB */ #endif /* no SLIM_SMT */ smt_timer_init(smc) ; /* timer package */ smt_agent_init(smc) ; /* SMT frame manager */ pcm_init(smc) ; /* PCM state machine */ ecm_init(smc) ; /* ECM state machine */ cfm_init(smc) ; /* CFM state machine */ rmt_init(smc) ; /* RMT state machine */ for (p = 0 ; p < NUMPHYS ; p++) { pcm(smc,p,0) ; /* PCM A state machine */ } ecm(smc,0) ; /* ECM state machine */ cfm(smc,0) ; /* CFM state machine */ rmt(smc,0) ; /* RMT state machine */ smt_agent_task(smc) ; /* NIF FSM etc */ PNMI_INIT(smc) ; /* PNMI initialization */ return(0) ; }
int cellAdecGetPcmItem(u32 handle, mem32_t pcmItem_ptr) { cellAdec.Log("cellAdecGetPcmItem(handle=%d, pcmItem_ptr_addr=0x%x)", handle, pcmItem_ptr.GetAddr()); AudioDecoder* adec; if (!Emu.GetIdManager().GetIDData(handle, adec)) { return CELL_ADEC_ERROR_ARG; } if (!pcmItem_ptr.IsGood()) { return CELL_ADEC_ERROR_FATAL; } AdecFrame& af = adec->frames.Peek(); if (adec->frames.IsEmpty()) { return CELL_ADEC_ERROR_EMPTY; } AVFrame* frame = af.data; mem_ptr_t<CellAdecPcmItem> pcm(adec->memAddr + adec->memBias); adec->memBias += 512; if (adec->memBias + 512 > adec->memSize) { adec->memBias = 0; } pcm->pcmHandle = 0; // ??? pcm->pcmAttr.bsiInfo_addr = pcm.GetAddr() + sizeof(CellAdecPcmItem); pcm->startAddr = 0x00000312; // invalid address (no output) pcm->size = af.size; pcm->status = CELL_OK; pcm->auInfo.pts.lower = af.pts; pcm->auInfo.pts.upper = af.pts >> 32; pcm->auInfo.size = af.auSize; pcm->auInfo.startAddr = af.auAddr; pcm->auInfo.userData = af.userdata; mem_ptr_t<CellAdecAtracXInfo> atx(pcm.GetAddr() + sizeof(CellAdecPcmItem)); atx->samplingFreq = frame->sample_rate; // ??? atx->nbytes = frame->nb_samples * frame->channels * sizeof(float); // ??? atx->channelConfigIndex = CELL_ADEC_CH_STEREO; // ??? pcmItem_ptr = pcm.GetAddr(); return CELL_OK; }
std::string AlsaLayer::buildDeviceTopo(const std::string &plugin, int card) { std::stringstream ss; std::string pcm(plugin); if (pcm == PCM_DEFAULT) return pcm; ss << ":" << card; return pcm + ss.str(); }
template <typename Numeric> void savePcmTest() { const std::size_t SIZE = 10; Numeric testArray[SIZE] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; Aquila::SignalSource data(testArray, SIZE, 22050); Aquila::RawPcmFile<Numeric>::save(data, Aquila_TEST_PCMFILE_OUTPUT); Aquila::RawPcmFile<Numeric> pcm(Aquila_TEST_PCMFILE_OUTPUT, 22050); CHECK_EQUAL(SIZE, pcm.getSamplesCount()); for (unsigned int i = 0; i < SIZE; ++i) { CHECK_CLOSE(testArray[i], pcm.sample(i), 0.000001); } }
size_t gcomm::PC::mtu() const { // TODO: if (gmcast_ == 0) gu_throw_fatal << "not open"; evs::UserMessage evsm; pc::UserMessage pcm(0, 0); if (gmcast_->mtu() < 2*evsm.serial_size() + pcm.serial_size()) { gu_throw_fatal << "transport max msg size too small: " << gmcast_->mtu(); } return gmcast_->mtu() - 2*evsm.serial_size() - pcm.serial_size(); }
int init(int freq,int channels,int bits,int size) { pcmsetting pcm(freq,channels,bits); if (bits==8) {mode=0;samplesize=1;} else {mode=1;samplesize=2;} if (waveOutOpen(&device,WAVE_MAPPER,&pcm.wf,0,(long)this,0)) return 1; buffersize=size; bnum=0; mix->freq=freq; mix->channels=channels; buffer.init(device,size*samplesize*32,0); timeSetEvent(5,5,audioTimerProc,(DWORD)this,TIME_ONESHOT);//PERIODIC ); timeout=0; playing=1; lagbuffers=6; flip(); buffer.play(device); return 0; }
void setup(const std::string& path) { Json json(path + "devdata/params.json"); picojson::object& params = json.value().get<picojson::object>()["audio"].get<picojson::object>(); int num = params.size(); buffer_.resize(num); alGenBuffers(num, &buffer_[0]); int idx = 0; int ch_max = 0; for(picojson::object::iterator it = params.begin(); it != params.end(); ++it) { picojson::object& obj = it->second.get<picojson::object>(); std::string file = path + "devdata/" + obj["file"].get<std::string>(); Pcm pcm(file); alBufferData(buffer_[idx], pcm.channel() == 1 ? AL_FORMAT_MONO16 : AL_FORMAT_STEREO16, pcm.data(), pcm.size(), pcm.rate()); std::string ch = obj["ch"].get<std::string>(); std::map<std::string, int>::iterator it_ch = ch_.find(ch); int ch_idx; if(it_ch == ch_.end()) { ch_[ch] = ch_max; ch_idx = ch_max; ++ch_max; } else { ch_idx = it_ch->second; } u_int type = obj["type"].get<double>(); { std::map<int, std::vector<u_int> >::iterator it = type_.find(type); if (it == type_.end()) { std::vector <u_int> v; v.push_back(ch_idx); type_.insert(std::map<int, std::vector<u_int> >::value_type(type, v)); } else { std::vector<u_int>::iterator itt = std::find(it->second.begin(), it->second.end(), ch_idx); if (itt == it->second.end()) { it->second.push_back(ch_idx); } } // チャンネルをタイプ別に積んでおく } SndObj sndobj; sndobj.id = idx; sndobj.ch = ch_idx; sndobj.loop = obj["loop"].get<bool>(); sndobj.gain = obj["gain"].get<double>(); sndobj.type = type; obj_[it->first] = sndobj; ++idx; } source_.resize(ch_max); alGenSources(ch_max, &source_[0]); ch_gain_.resize(ch_max); std::fill(ch_gain_.begin(), ch_gain_.end(), 0.0); }
NAMESPACE_CONVIMP3_START bool Codec::encode( const char *in_file, const char *out_file ) { wave::Wave pcm( in_file ); unsigned sample_rate = pcm.get_samples_per_sec(); unsigned byte_rate = pcm.get_avg_bytes_per_sec(); unsigned channels = pcm.get_channels(); std::ofstream mp3( out_file, std::ios_base::binary | std::ios_base::out ); const int PCM_SIZE = 8192; const int MP3_SIZE = 8192; unsigned offset = 0; std::vector<char> pcm_buffer; pcm_buffer.reserve( sizeof(short int) * PCM_SIZE * 2 ); unsigned char mp3_buffer[MP3_SIZE]; lameplus::LamePlus l; l.set_in_samplerate( sample_rate ); l.set_brate( byte_rate ); if( channels == 1 ) { l.set_num_channels( 1 ); l.set_mode( MONO ); } else { l.set_num_channels( channels ); } l.set_VBR( vbr_default ); l.init_params(); while( true ) { int k = ( channels == 1 ) ? 1 : 2; unsigned size = PCM_SIZE * k * sizeof( short int ); pcm.get_samples( offset, size, pcm_buffer ); unsigned read = pcm_buffer.size(); offset += read; if( read > 0 ) { unsigned read_shorts = read / 2; // need number of 'short int' read int write = 0; if( channels == 1 ) { write = l.encode_buffer( reinterpret_cast<short int*>( &pcm_buffer[0] ), NULL, read_shorts, mp3_buffer, MP3_SIZE ); } else { write = l.encode_buffer_interleaved( reinterpret_cast<short int*>( &pcm_buffer[0] ), read_shorts, mp3_buffer, MP3_SIZE ); } pcm_buffer.clear(); mp3.write( reinterpret_cast<char*>( mp3_buffer ) , write ); } if( read < size ) { int write = l.encode_flush( mp3_buffer, MP3_SIZE ); mp3.write( reinterpret_cast<char*>( mp3_buffer ), write ); break; } }; return true; }
void projectM::projectM_init ( int gx, int gy, int fps, int texsize, int width, int height ) { /** Initialise engine variables */ projectM_initengine(); presetInputs.Initialize ( gx, gy ); presetInputs2.Initialize ( gx, gy ); presetOutputs.Initialize ( gx, gy ); presetOutputs2.Initialize ( gx, gy ); /** Initialise start time */ timeKeeper = new TimeKeeper(_settings.presetDuration,_settings.smoothPresetDuration, _settings.easterEgg); /** Nullify frame stash */ /** Initialise per-pixel matrix calculations */ presetInputs.fps = fps; presetInputs2.fps = fps; /** We need to initialise this before the builtin param db otherwise bass/mid etc won't bind correctly */ assert ( !beatDetect ); std::cerr << "pcm new" << std::endl; if (!_pcm) _pcm = new PCM(); assert(pcm()); beatDetect = new BeatDetect ( _pcm ); this->renderer = new Renderer(width, height, gx, gy, texsize, beatDetect, settings().presetURL, settings().titleFontURL, settings().menuFontURL); running = true; initPresetTools(); if ( presetInputs.fps > 0 ) mspf= ( int ) ( 1000.0/ ( float ) presetInputs.fps ); else mspf = 0; this->presetInputs.gx = gx; this->presetInputs.gy = gy; this->presetInputs2.gx = gx; this->presetInputs2.gy = gy; #ifdef USE_THREADS pthread_mutex_init(&mutex, NULL); pthread_cond_init(&condition, NULL); if (pthread_create(&thread, NULL, thread_callback, this) != 0) { printf("oops\n"); exit(1); } pthread_mutex_lock( &mutex ); printf("got lock\n"); #endif renderer->setPresetName ( m_activePreset->presetName() ); timeKeeper->StartPreset(); assert(pcm()); // printf ( "exiting projectM_init()\n" ); }