void SawtoothSoundComponent_HW::init(){ m_FrequencyIn_1_Port->registerCallback(ICallbackPtr(new OnFrequencyChange(*this))); /* initialize reconos */ if(slot.isValid()){ // TODO: Warum werden hier zwei message boxen benötigt!? /* initialize message boxes with 1 data word */ mbox_init(&m_CtrlStart, 1); mbox_init(&m_CtrlStop, 1); m_HWTParams[0] = (uint32_t) m_LocalBuffer; m_HWTParams[1] = 0; m_HWTParams[2] = (uint32_t) (getPhaseIncrement(440) * SOUNDGATES_FIXED_PT_SCALE); m_ReconOSResource[0].type = RECONOS_TYPE_MBOX; m_ReconOSResource[0].ptr = &m_CtrlStart; m_ReconOSResource[1].type = RECONOS_TYPE_MBOX; m_ReconOSResource[1].ptr = &m_CtrlStop; reconos_hwt_setresources(&m_ReconOSThread, &m_ReconOSResource[0], 2); reconos_hwt_setinitdata(&m_ReconOSThread, (void *) &m_HWTParams[0]); reconos_hwt_create(&m_ReconOSThread, slot.getSlot(), NULL); m_SoundOut_1_Port->clearWriteBuffer(); } }
void SawtoothSoundComponent::init() { m_SoundOut_1_Port->init(); m_FrequencyIn_1_Port->registerCallback( ICallbackPtr(new OnFrequencyChange(*this))); }
void TemplateSoundComponent::init() { // You can init() sound output ports to clear their buffers m_TemplateSoundOut_2_Port->init(); // Control values can trigger a callback function when they change. m_TemplateControlIn_1_Port->registerCallback(ICallbackPtr(new OnChange(*this))); }
void LoggingComponent::init() { // Control values can trigger a callback function when they change. m_Trigger_2_Port->registerCallback(ICallbackPtr(new OnChange(*this))); }
void MulCCComponent::init(void) { m_ControlIn_1_Port->registerCallback(ICallbackPtr(new OnChange1(*this))); m_ControlIn_2_Port->registerCallback(ICallbackPtr(new OnChange2(*this))); }
void SamplePlayer_SW::init() { AVPacket avpkt; ReSampleContext* resmplCtx; int compressed_bytes_consumed = 0; int compressed_file_size = 0; uint8_t* l_ResampleBuffer; initCodec(); /* Initialize audio codec */ av_init_packet(&avpkt); /* Initialize packet */ // resmplCtx = av_audio_resample_init(m_CodecCtx->channels, // m_CodecCtx->channels, // Synthesizer::config::samplerate, // m_CodecCtx->sample_rate, // AV_SAMPLE_FMT_S32, // m_CodecCtx->sample_fmt, // 16, 10, 0, 1.0); m_DecompressedDataBuffer = new uint8_t[AVCODEC_MAX_AUDIO_FRAME_SIZE * MAX_PLAYBACK_LENGTH_SEC]; memset(m_DecompressedDataBuffer, 0 ,AVCODEC_MAX_AUDIO_FRAME_SIZE * MAX_PLAYBACK_LENGTH_SEC); LOG_DEBUG("Decoding audio file"); LOG_DEBUG("Sample format:" << av_get_sample_fmt_name(m_CodecCtx->sample_fmt)); while (!av_read_frame(m_ContainerCtx, &avpkt)) { int got_frame = 0; if (!m_Decoded_Frame) { if (!(m_Decoded_Frame = avcodec_alloc_frame())) { /* allocate once */ LOG_ERROR("Could not allocate audio frame"); exit(1); } }else{ avcodec_get_frame_defaults(m_Decoded_Frame); } compressed_bytes_consumed = avcodec_decode_audio4(m_CodecCtx, m_Decoded_Frame, &got_frame, &avpkt); if (compressed_bytes_consumed < 0) { LOG_ERROR("Error while decoding audio frame"); exit(1); } if (got_frame) { int samples_written = 0; int data_size = 0; size_t resampled_Bytes = 0; /* if a frame has been decoded, output it */ data_size = av_samples_get_buffer_size(NULL, m_CodecCtx->channels, m_Decoded_Frame->nb_samples, m_CodecCtx->sample_fmt, 1); int32_t* buf = (int32_t*) (m_DecompressedDataBuffer + m_DecompressedDataSize); switch(m_CodecCtx->sample_fmt){ case AV_SAMPLE_FMT_NONE: case AV_SAMPLE_FMT_U8: // for(int i = 0; i < m_Decoded_Frame->nb_samples * m_CodecCtx->channels; i++){ // buf[i] = (int32_t)( ((int8_t*) m_Decoded_Frame->data[0])[i] << 24 ); // } // break; //FIXME: convert other sample formats case AV_SAMPLE_FMT_S16: for(int i = 0; i < m_Decoded_Frame->nb_samples * m_CodecCtx->channels; i++){ buf[i] = *(((short*)m_Decoded_Frame->data[0]) + i) << 16; } m_DecompressedDataSize += m_Decoded_Frame->nb_samples * m_CodecCtx->channels * av_get_bytes_per_sample(AV_SAMPLE_FMT_S32); break; case AV_SAMPLE_FMT_S32: memcpy(m_DecompressedDataBuffer + m_DecompressedDataSize, m_Decoded_Frame->data[0], data_size); m_DecompressedDataSize += data_size; break; case AV_SAMPLE_FMT_FLT: case AV_SAMPLE_FMT_DBL: case AV_SAMPLE_FMT_U8P: case AV_SAMPLE_FMT_S16P: case AV_SAMPLE_FMT_S32P: case AV_SAMPLE_FMT_FLTP: case AV_SAMPLE_FMT_DBLP: default: LOG_ERROR("Sample format is not supported"); } } } char* writeLeftPortPtr = m_SoundOut_Left_1_Port->getWriteBuffer(); // char* writeRightPortPtr = m_SoundOut_Right_2_Port->getWriteBuffer(); memset(writeLeftPortPtr, 0, Synthesizer::config::bytesPerBlock); // memset(writeRightPortPtr, 0, Synthesizer::config::bytesPerBlock); m_Trigger_1_Port->registerCallback(ICallbackPtr(new OnValueChange<int, ControlPortPtr>(m_DoPlayback, m_Trigger_1_Port))); // audio_resample_close(resmplCtx); // av_free(m_CodecCtx); // av_free(m_Decoded_Frame); // avformat_free_context(m_ContainerCtx); }
void SubSCComponent::init(void) { m_ControlIn_2_Port->registerCallback(ICallbackPtr(new OnChange(*this))); }