示例#1
0
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 = growing_fifo_new();
	return true;
}
示例#2
0
static bool
wave_encoder_open(struct encoder *_encoder,
		  G_GNUC_UNUSED struct audio_format *audio_format,
		  G_GNUC_UNUSED GError **error)
{
	struct wave_encoder *encoder = (struct wave_encoder *)_encoder;

	assert(audio_format_valid(audio_format));

	switch (audio_format->format) {
	case SAMPLE_FORMAT_S8:
		encoder->bits = 8;
		break;

	case SAMPLE_FORMAT_S16:
		encoder->bits = 16;
		break;

	case SAMPLE_FORMAT_S24:
		audio_format->format = SAMPLE_FORMAT_S24_P32;
		encoder->bits = 24;
		break;

	case SAMPLE_FORMAT_S24_P32:
		encoder->bits = 24;
		break;

	case SAMPLE_FORMAT_S32:
		encoder->bits = 32;
		break;

	default:
		audio_format->format = SAMPLE_FORMAT_S16;
		encoder->bits = 16;
		break;
	}

	encoder->buffer = growing_fifo_new();
	struct wave_header *header =
		growing_fifo_write(&encoder->buffer, sizeof(*header));

	/* create PCM wave header in initial buffer */
	fill_wave_header(header,
			audio_format->channels,
			 encoder->bits,
			audio_format->sample_rate,
			 (encoder->bits / 8) * audio_format->channels );
	fifo_buffer_append(encoder->buffer, sizeof(*header));

	return true;
}
示例#3
0
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;
	}

	pcm_buffer_init(&encoder->expand_buffer);

	encoder->output_buffer = growing_fifo_new();

	/* this immediately outputs data through callback */

	{
		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;
		}
	}

	return true;
}