void pcm_resample_lsr_init(struct pcm_resample_state *state) { memset(state, 0, sizeof(*state)); pcm_buffer_init(&state->in); pcm_buffer_init(&state->out); pcm_buffer_init(&state->buffer); }
void pcm_convert_init(struct pcm_convert_state *state) { memset(state, 0, sizeof(*state)); pcm_resample_init(&state->resample); pcm_dither_24_init(&state->dither); pcm_buffer_init(&state->format_buffer); pcm_buffer_init(&state->pack_buffer); pcm_buffer_init(&state->channels_buffer); pcm_buffer_init(&state->byteswap_buffer); }
static const struct audio_format * route_filter_open(struct filter *_filter, struct audio_format *audio_format, G_GNUC_UNUSED GError **error_r) { struct route_filter *filter = (struct route_filter *)_filter; // Copy the input format for later reference filter->input_format = *audio_format; filter->input_frame_size = audio_format_frame_size(&filter->input_format); // Decide on an output format which has enough channels, // and is otherwise identical filter->output_format = *audio_format; filter->output_format.channels = filter->min_output_channels; // Precalculate this simple value, to speed up allocation later filter->output_frame_size = audio_format_frame_size(&filter->output_format); // This buffer grows as needed pcm_buffer_init(&filter->output_buffer); return &filter->output_format; }
void pcm_dsd_init(struct pcm_dsd *dsd) { pcm_buffer_init(&dsd->buffer); memset(dsd->dsd2pcm, 0, sizeof(dsd->dsd2pcm)); }
static bool winmm_output_open(void *data, struct audio_format *audio_format, GError **error_r) { struct winmm_output *wo = data; wo->event = CreateEvent(NULL, false, false, NULL); if (wo->event == NULL) { g_set_error(error_r, winmm_output_quark(), 0, "CreateEvent() failed"); return false; } switch (audio_format->format) { case SAMPLE_FORMAT_S8: case SAMPLE_FORMAT_S16: break; case SAMPLE_FORMAT_S24: case SAMPLE_FORMAT_S24_P32: case SAMPLE_FORMAT_S32: case SAMPLE_FORMAT_UNDEFINED: /* we havn't tested formats other than S16 */ audio_format->format = SAMPLE_FORMAT_S16; break; } if (audio_format->channels > 2) /* same here: more than stereo was not tested */ audio_format->channels = 2; WAVEFORMATEX format; format.wFormatTag = WAVE_FORMAT_PCM; format.nChannels = audio_format->channels; format.nSamplesPerSec = audio_format->sample_rate; format.nBlockAlign = audio_format_frame_size(audio_format); format.nAvgBytesPerSec = format.nSamplesPerSec * format.nBlockAlign; format.wBitsPerSample = audio_format_sample_size(audio_format) * 8; format.cbSize = 0; MMRESULT result = waveOutOpen(&wo->handle, wo->device_id, &format, (DWORD_PTR)wo->event, 0, CALLBACK_EVENT); if (result != MMSYSERR_NOERROR) { CloseHandle(wo->event); g_set_error(error_r, winmm_output_quark(), result, "waveOutOpen() failed"); return false; } for (unsigned i = 0; i < G_N_ELEMENTS(wo->buffers); ++i) { pcm_buffer_init(&wo->buffers[i].buffer); memset(&wo->buffers[i].hdr, 0, sizeof(wo->buffers[i].hdr)); } wo->next_buffer = 0; return true; }
static const struct audio_format * volume_filter_open(struct filter *_filter, struct audio_format *audio_format, G_GNUC_UNUSED GError **error_r) { struct volume_filter *filter = (struct volume_filter *)_filter; filter->audio_format = *audio_format; pcm_buffer_init(&filter->buffer); return &filter->audio_format; }
/* Start playback (implies song load) */ static int sndtst_start(const char *fn, int track, playa_info_t *info) { int err = -1; int i, frq; float a, stp; const float amp = 14000; char tmp[128]; SDDEBUG("%s([%s])\n", fn); SDINDENT; frq = get_frq(fn); pcm_current = 0; pcm_count = 44100 / frq; if (pcm_buffer_init(pcm_count, 0)) { goto error; } for (i=0, a=0, stp=2.0*MF_PI/(float)pcm_count; i<pcm_count; i++, a += stp) { pcm_buffer[i] = Sin(a) * amp; } playa_info_bits(info,16); playa_info_stereo(info, 0); /* 1 = stereo ? BeN : yes that's it :) */ playa_info_frq(info,44100); #if 0 playa_info_bps(info,4*44100); playa_info_bytes(info,pcm_count*4); /* ? BeN: only for streaming, but anyway if you want to set it : x4 (x2:short x2:stereo */ playa_info_time(info, 100000); #endif playa_info_genre(info, "head-ache"); playa_info_comments(info, "What a nice sound , isn't it ?"); sprintf(tmp,"%dhz sinus generator", (int)frq); playa_info_desc(info, tmp); sprintf(tmp,"%dhz sinus", (int)frq); playa_info_title(info, tmp); /* sndtst_info(info, 0);*/ err = 0; error: if (err) { pcm_buffer_shutdown(); } SDUNINDENT; SDDEBUG("%s() := [%d]\n", __FUNCTION__, err); return err; }
static struct encoder * wave_encoder_init(G_GNUC_UNUSED const struct config_param *param, G_GNUC_UNUSED GError **error) { struct wave_encoder *encoder; encoder = g_new(struct wave_encoder, 1); encoder_struct_init(&encoder->encoder, &wave_encoder_plugin); pcm_buffer_init(&encoder->buffer); return &encoder->encoder; }
static bool null_encoder_open(struct encoder *_encoder, G_GNUC_UNUSED struct audio_format *audio_format, G_GNUC_UNUSED GError **error) { struct null_encoder *encoder = (struct null_encoder *)_encoder; encoder->buffer_length = 0; pcm_buffer_init(&encoder->buffer); return true; }
static const struct audio_format * replay_gain_filter_open(struct filter *_filter, struct audio_format *audio_format, G_GNUC_UNUSED GError **error_r) { struct replay_gain_filter *filter = (struct replay_gain_filter *)_filter; audio_format->reverse_endian = false; filter->audio_format = *audio_format; pcm_buffer_init(&filter->buffer); return &filter->audio_format; }
static const struct audio_format * normalize_filter_open(struct filter *_filter, struct audio_format *audio_format, G_GNUC_UNUSED GError **error_r) { struct normalize_filter *filter = (struct normalize_filter *)_filter; audio_format->format = SAMPLE_FORMAT_S16; filter->compressor = Compressor_new(0); pcm_buffer_init(&filter->buffer); return audio_format; }
void flac_data_init(struct flac_data *data, struct decoder * decoder, struct input_stream *input_stream) { pcm_buffer_init(&data->buffer); data->unsupported = false; data->initialized = false; data->total_frames = 0; data->first_frame = 0; data->next_frame = 0; data->position = 0; data->decoder = decoder; data->input_stream = input_stream; data->tag = NULL; }
bool audio_output_init(struct audio_output *ao, const struct config_param *param, GError **error_r) { const struct audio_output_plugin *plugin = NULL; GError *error = NULL; if (param) { const char *p; p = config_get_block_string(param, AUDIO_OUTPUT_TYPE, NULL); if (p == NULL) { g_set_error(error_r, audio_output_quark(), 0, "Missing \"type\" configuration"); return false; } plugin = audio_output_plugin_get(p); if (plugin == NULL) { g_set_error(error_r, audio_output_quark(), 0, "No such audio output plugin: %s", p); return false; } ao->name = config_get_block_string(param, AUDIO_OUTPUT_NAME, NULL); if (ao->name == NULL) { g_set_error(error_r, audio_output_quark(), 0, "Missing \"name\" configuration"); return false; } p = config_get_block_string(param, AUDIO_OUTPUT_FORMAT, NULL); if (p != NULL) { bool success = audio_format_parse(&ao->config_audio_format, p, true, error_r); if (!success) return false; } else audio_format_clear(&ao->config_audio_format); } else { g_warning("No \"%s\" defined in config file\n", CONF_AUDIO_OUTPUT); plugin = audio_output_detect(error_r); if (plugin == NULL) return false; g_message("Successfully detected a %s audio device", plugin->name); ao->name = "default detected output"; audio_format_clear(&ao->config_audio_format); } ao->plugin = plugin; ao->always_on = config_get_block_bool(param, "always_on", false); ao->enabled = config_get_block_bool(param, "enabled", true); ao->really_enabled = false; ao->open = false; ao->pause = false; ao->fail_timer = NULL; pcm_buffer_init(&ao->cross_fade_buffer); /* set up the filter chain */ ao->filter = filter_chain_new(); assert(ao->filter != NULL); /* create the replay_gain filter */ const char *replay_gain_handler = config_get_block_string(param, "replay_gain_handler", "software"); if (strcmp(replay_gain_handler, "none") != 0) { ao->replay_gain_filter = filter_new(&replay_gain_filter_plugin, param, NULL); assert(ao->replay_gain_filter != NULL); ao->replay_gain_serial = 0; ao->other_replay_gain_filter = filter_new(&replay_gain_filter_plugin, param, NULL); assert(ao->other_replay_gain_filter != NULL); ao->other_replay_gain_serial = 0; } else { ao->replay_gain_filter = NULL; ao->other_replay_gain_filter = NULL; } /* create the normalization filter (if configured) */ if (config_get_bool(CONF_VOLUME_NORMALIZATION, false)) { struct filter *normalize_filter = filter_new(&normalize_filter_plugin, NULL, NULL); assert(normalize_filter != NULL); filter_chain_append(ao->filter, autoconvert_filter_new(normalize_filter)); } filter_chain_parse(ao->filter, config_get_block_string(param, AUDIO_FILTERS, ""), &error ); // It's not really fatal - Part of the filter chain has been set up already // and even an empty one will work (if only with unexpected behaviour) if (error != NULL) { g_warning("Failed to initialize filter chain for '%s': %s", ao->name, error->message); g_error_free(error); } ao->thread = NULL; ao->command = AO_COMMAND_NONE; ao->mutex = g_mutex_new(); ao->cond = g_cond_new(); ao->data = ao_plugin_init(plugin, &ao->config_audio_format, param, error_r); if (ao->data == NULL) return false; ao->mixer = audio_output_load_mixer(ao->data, param, plugin->mixer_plugin, ao->filter, &error); if (ao->mixer == NULL && error != NULL) { g_warning("Failed to initialize hardware mixer for '%s': %s", ao->name, error->message); g_error_free(error); } /* use the hardware mixer for replay gain? */ if (strcmp(replay_gain_handler, "mixer") == 0) { if (ao->mixer != NULL) replay_gain_filter_set_mixer(ao->replay_gain_filter, ao->mixer, 100); else g_warning("No such mixer for output '%s'", ao->name); } else if (strcmp(replay_gain_handler, "software") != 0 && ao->replay_gain_filter != NULL) { g_set_error(error_r, audio_output_quark(), 0, "Invalid \"replay_gain_handler\" value"); return false; } /* the "convert" filter must be the last one in the chain */ ao->convert_filter = filter_new(&convert_filter_plugin, NULL, NULL); assert(ao->convert_filter != NULL); filter_chain_append(ao->filter, ao->convert_filter); /* done */ return true; }
static struct input_stream * input_cdio_open(const char *uri, GMutex *mutex, GCond *cond, GError **error_r) { struct input_cdio_paranoia *i; struct cdio_uri parsed_uri; if (!parse_cdio_uri(&parsed_uri, uri, error_r)) return NULL; i = g_new(struct input_cdio_paranoia, 1); input_stream_init(&i->base, &input_plugin_cdio_paranoia, uri, mutex, cond); /* initialize everything (should be already) */ i->drv = NULL; i->cdio = NULL; i->para = NULL; i->trackno = parsed_uri.track; pcm_buffer_init(&i->conv_buffer); /* get list of CD's supporting CD-DA */ char *device = parsed_uri.device[0] != 0 ? g_strdup(parsed_uri.device) : cdio_detect_device(); if (device == NULL) { g_set_error(error_r, cdio_quark(), 0, "Unable find or access a CD-ROM drive with an audio CD in it."); input_cdio_close(&i->base); return NULL; } /* Found such a CD-ROM with a CD-DA loaded. Use the first drive in the list. */ i->cdio = cdio_open(device, DRIVER_UNKNOWN); g_free(device); i->drv = cdio_cddap_identify_cdio(i->cdio, 1, NULL); if ( !i->drv ) { g_set_error(error_r, cdio_quark(), 0, "Unable to identify audio CD disc."); input_cdio_close(&i->base); return NULL; } cdda_verbose_set(i->drv, CDDA_MESSAGE_FORGETIT, CDDA_MESSAGE_FORGETIT); if ( 0 != cdio_cddap_open(i->drv) ) { g_set_error(error_r, cdio_quark(), 0, "Unable to open disc."); input_cdio_close(&i->base); return NULL; } i->endian = data_bigendianp(i->drv); switch (i->endian) { case -1: g_debug("cdda: drive returns unknown audio data, assuming Little Endian"); i->endian = 0; break; case 0: g_debug("cdda: drive returns audio data Little Endian."); break; case 1: g_debug("cdda: drive returns audio data Big Endian."); break; default: g_set_error(error_r, cdio_quark(), 0, "Drive returns unknown data type %d", i->endian); input_cdio_close(&i->base); return NULL; } i->lsn_relofs = 0; if (i->trackno >= 0) { i->lsn_from = cdio_get_track_lsn(i->cdio, i->trackno); i->lsn_to = cdio_get_track_last_lsn(i->cdio, i->trackno); } else { i->lsn_from = 0; i->lsn_to = cdio_get_disc_last_lsn(i->cdio); } i->para = cdio_paranoia_init(i->drv); /* Set reading mode for full paranoia, but allow skipping sectors. */ paranoia_modeset(i->para, PARANOIA_MODE_FULL^PARANOIA_MODE_NEVERSKIP); /* seek to beginning of the track */ cdio_paranoia_seek(i->para, i->lsn_from, SEEK_SET); i->base.ready = true; i->base.seekable = true; i->base.size = (i->lsn_to - i->lsn_from + 1) * CDIO_CD_FRAMESIZE_RAW; /* hack to make MPD select the "pcm" decoder plugin */ i->base.mime = g_strdup("audio/x-mpd-cdda-pcm"); return &i->base; }
static bool flac_encoder_open(struct encoder *_encoder, struct audio_format *audio_format, GError **error) { struct flac_encoder *encoder = (struct flac_encoder *)_encoder; unsigned bits_per_sample; encoder->audio_format = *audio_format; /* FIXME: flac should support 32bit as well */ switch (audio_format->format) { case SAMPLE_FORMAT_S8: bits_per_sample = 8; break; case SAMPLE_FORMAT_S16: bits_per_sample = 16; break; case SAMPLE_FORMAT_S24_P32: bits_per_sample = 24; break; default: bits_per_sample = 24; audio_format->format = SAMPLE_FORMAT_S24_P32; } /* allocate the encoder */ encoder->fse = FLAC__stream_encoder_new(); if (encoder->fse == NULL) { g_set_error(error, flac_encoder_quark(), 0, "flac_new() failed"); return false; } if (!flac_encoder_setup(encoder, bits_per_sample, error)) { FLAC__stream_encoder_delete(encoder->fse); return false; } encoder->buffer_length = 0; pcm_buffer_init(&encoder->buffer); pcm_buffer_init(&encoder->expand_buffer); /* this immediately outputs data through callback */ #if !defined(FLAC_API_VERSION_CURRENT) || FLAC_API_VERSION_CURRENT <= 7 { FLAC__StreamEncoderState init_status; FLAC__stream_encoder_set_write_callback(encoder->fse, flac_write_callback); init_status = FLAC__stream_encoder_init(encoder->fse); if (init_status != FLAC__STREAM_ENCODER_OK) { g_set_error(error, flac_encoder_quark(), 0, "failed to initialize encoder: %s\n", FLAC__StreamEncoderStateString[init_status]); flac_encoder_close(_encoder); return false; } } #else { FLAC__StreamEncoderInitStatus init_status; init_status = FLAC__stream_encoder_init_stream(encoder->fse, flac_write_callback, NULL, NULL, NULL, encoder); if(init_status != FLAC__STREAM_ENCODER_INIT_STATUS_OK) { g_set_error(error, flac_encoder_quark(), 0, "failed to initialize encoder: %s\n", FLAC__StreamEncoderInitStatusString[init_status]); flac_encoder_close(_encoder); return false; } } #endif return true; }