Lines Matching defs:psf
53 static int mpeg_l3_encoder_close (SF_PRIVATE *psf) ;
54 static int mpeg_l3_encoder_construct (SF_PRIVATE *psf) ;
55 static int mpeg_l3_encoder_byterate (SF_PRIVATE *psf) ;
57 static sf_count_t mpeg_l3_encode_write_short_stereo (SF_PRIVATE *psf, const short *ptr, sf_count_t len) ;
58 static sf_count_t mpeg_l3_encode_write_int_stereo (SF_PRIVATE *psf, const int *ptr, sf_count_t len) ;
59 static sf_count_t mpeg_l3_encode_write_float_stereo (SF_PRIVATE *psf, const float *ptr, sf_count_t len) ;
60 static sf_count_t mpeg_l3_encode_write_double_stereo (SF_PRIVATE *psf, const double *ptr, sf_count_t len) ;
61 static sf_count_t mpeg_l3_encode_write_short_mono (SF_PRIVATE *psf, const short *ptr, sf_count_t len) ;
62 static sf_count_t mpeg_l3_encode_write_int_mono (SF_PRIVATE *psf, const int *ptr, sf_count_t len) ;
63 static sf_count_t mpeg_l3_encode_write_float_mono (SF_PRIVATE *psf, const float *ptr, sf_count_t len) ;
64 static sf_count_t mpeg_l3_encode_write_double_mono (SF_PRIVATE *psf, const double *ptr, sf_count_t len) ;
71 mpeg_l3_encoder_init (SF_PRIVATE *psf, int info_tag)
74 if (psf->file.mode == SFM_RDWR)
77 if (psf->file.mode != SFM_WRITE)
80 psf->codec_data = pmpeg = calloc (1, sizeof (MPEG_L3_ENC_PRIVATE)) ;
84 if (psf->sf.channels < 1 || psf->sf.channels > 2)
92 lame_set_in_samplerate (pmpeg->lamef, psf->sf.samplerate) ;
93 lame_set_num_channels (pmpeg->lamef, psf->sf.channels) ;
94 if (lame_set_out_samplerate (pmpeg->lamef, psf->sf.samplerate) < 0)
99 if (!info_tag || psf->is_pipe)
104 if (psf->sf.channels == 2)
105 { psf->write_short = mpeg_l3_encode_write_short_stereo ;
106 psf->write_int = mpeg_l3_encode_write_int_stereo ;
107 psf->write_float = mpeg_l3_encode_write_float_stereo ;
108 psf->write_double = mpeg_l3_encode_write_double_stereo ;
111 { psf->write_short = mpeg_l3_encode_write_short_mono ;
112 psf->write_int = mpeg_l3_encode_write_int_mono ;
113 psf->write_float = mpeg_l3_encode_write_float_mono ;
114 psf->write_double = mpeg_l3_encode_write_double_mono ;
117 psf->sf.seekable = 0 ;
118 psf->codec_close = mpeg_l3_encoder_close ;
119 psf->byterate = mpeg_l3_encoder_byterate ;
120 psf->datalength = 0 ;
126 mpeg_l3_encoder_write_id3tag (SF_PRIVATE *psf)
127 { MPEG_L3_ENC_PRIVATE *pmpeg = (MPEG_L3_ENC_PRIVATE *) psf->codec_data ;
131 if (psf->have_written)
134 if ((i = mpeg_l3_encoder_construct (psf)))
137 if (psf_fseek (psf, 0, SEEK_SET) != 0)
144 { switch (psf->strings.data [i].type)
146 id3tag_set_title (pmpeg->lamef, psf->strings.storage + psf->strings.data [i].offset) ;
150 id3tag_set_artist (pmpeg->lamef, psf->strings.storage + psf->strings.data [i].offset) ;
154 id3tag_set_album (pmpeg->lamef, psf->strings.storage + psf->strings.data [i].offset) ;
158 id3tag_set_year (pmpeg->lamef, psf->strings.storage + psf->strings.data [i].offset) ;
162 id3tag_set_comment (pmpeg->lamef, psf->strings.storage + psf->strings.data [i].offset) ;
166 id3tag_set_genre (pmpeg->lamef, psf->strings.storage + psf->strings.data [i].offset) ;
170 id3tag_set_track (pmpeg->lamef, psf->strings.storage + psf->strings.data [i].offset) ;
181 { psf_log_printf (psf, "Writing ID3v2 header.\n") ;
185 psf_fwrite (id3v2_buffer, 1, id3v2_size, psf) ;
186 psf->dataoffset = id3v2_size ;
194 mpeg_l3_encoder_set_quality (SF_PRIVATE *psf, double compression)
195 { MPEG_L3_ENC_PRIVATE *pmpeg = (MPEG_L3_ENC_PRIVATE *) psf->codec_data ;
209 bitrate_mode = mpeg_l3_encoder_get_bitrate_mode (psf) ;
215 if (psf->sf.samplerate >= 32000)
219 else if (psf->sf.samplerate >= 16000)
237 psf_log_printf (psf, "Failed to set lame encoder quality.\n") ;
242 mpeg_l3_encoder_set_bitrate_mode (SF_PRIVATE *psf, int mode)
243 { MPEG_L3_ENC_PRIVATE *pmpeg = (MPEG_L3_ENC_PRIVATE *) psf->codec_data ;
247 { psf->error = SFE_CMD_HAS_DATA ;
256 psf->error = SFE_BAD_COMMAND_PARAM ;
262 return mpeg_l3_encoder_set_quality (psf, pmpeg->compression) ;
265 psf_log_printf (psf, "Failed to set LAME vbr mode to %d.\n", vbr_mode) ;
270 mpeg_l3_encoder_get_bitrate_mode (SF_PRIVATE *psf)
271 { MPEG_L3_ENC_PRIVATE *pmpeg = (MPEG_L3_ENC_PRIVATE *) psf->codec_data ;
284 psf->error = SFE_INTERNAL ;
294 mpeg_l3_encoder_close (SF_PRIVATE *psf)
295 { MPEG_L3_ENC_PRIVATE* pmpeg = (MPEG_L3_ENC_PRIVATE *) psf->codec_data ;
306 psf_fwrite (buffer, 1, ret, psf) ;
314 { psf_log_printf (psf, " Writing ID3v1 trailer.\n") ;
315 psf_fwrite (buffer, 1, ret, psf) ;
334 psf_log_printf (psf, " Writing LAME info header at offset %d, %d bytes.\n",
335 psf->dataoffset, len) ;
337 pos = psf_ftell (psf) ;
338 if (psf_fseek (psf, psf->dataoffset, SEEK_SET) == psf->dataoffset)
339 { psf_fwrite (buffer, 1, ret, psf) ;
340 psf_fseek (psf, pos, SEEK_SET) ;
357 mpeg_l3_encoder_log_config (SF_PRIVATE *psf, lame_t lamef)
373 psf_log_printf (psf, " MPEG Version : %s\n", version) ;
374 psf_log_printf (psf, " Block samples : %d\n", lame_get_framesize (lamef)) ;
375 psf_log_printf (psf, " Channel mode : %s\n", chn_mode) ;
376 psf_log_printf (psf, " Samplerate : %d\n", lame_get_out_samplerate (lamef)) ;
377 psf_log_printf (psf, " Encoder mode : ") ;
380 psf_log_printf (psf, "CBR\n") ;
381 psf_log_printf (psf, " Bitrate : %d kbps\n", lame_get_brate (lamef)) ;
384 psf_log_printf (psf, "ABR\n") ;
385 psf_log_printf (psf, " Mean Bitrate : %d kbps\n", lame_get_VBR_mean_bitrate_kbps (lamef)) ;
390 psf_log_printf (psf, "VBR\n") ;
391 psf_log_printf (psf, " Quality : %d\n", lame_get_VBR_q (lamef)) ;
395 psf_log_printf (psf, "Unknown!? (%d)\n", lame_get_VBR (lamef)) ;
399 psf_log_printf (psf, " Encoder delay : %d\n", lame_get_encoder_delay (lamef)) ;
400 psf_log_printf (psf, " Write INFO header : %d\n", lame_get_bWriteVbrTag (lamef)) ;
404 mpeg_l3_encoder_construct (SF_PRIVATE *psf)
405 { MPEG_L3_ENC_PRIVATE *pmpeg = (MPEG_L3_ENC_PRIVATE *) psf->codec_data ;
410 { psf_log_printf (psf, "Failed to initialize lame encoder!\n") ;
414 psf_log_printf (psf, "Initialized LAME encoder.\n") ;
415 mpeg_l3_encoder_log_config (psf, pmpeg->lamef) ;
424 pmpeg->frame_samples = frame_samples_per_channel * psf->sf.channels ;
437 mpeg_l3_encoder_byterate (SF_PRIVATE *psf)
438 { MPEG_L3_ENC_PRIVATE *pmpeg = (MPEG_L3_ENC_PRIVATE *) psf->codec_data ;
443 bitrate_mode = mpeg_l3_encoder_get_bitrate_mode (psf) ;
451 calculated_byterate = psf_ftell (psf) - psf->dataoffset ;
452 calculated_byterate /= (float) psf->write_current ;
453 calculated_byterate *= (float) psf->sf.samplerate ;
462 mpeg_l3_encode_write_short_mono (SF_PRIVATE *psf, const short *ptr, sf_count_t len)
463 { MPEG_L3_ENC_PRIVATE *pmpeg = (MPEG_L3_ENC_PRIVATE*) psf->codec_data ;
467 if ((psf->error = mpeg_l3_encoder_construct (psf)))
475 { psf_log_printf (psf, "lame_encode_buffer returned %d\n", nbytes) ;
480 { writen = psf_fwrite (pmpeg->block, 1, nbytes, psf) ;
482 { psf_log_printf (psf, "*** Warning : short write (%d != %d).\n", writen, nbytes) ;
495 mpeg_l3_encode_write_short_stereo (SF_PRIVATE *psf, const short *ptr, sf_count_t len)
497 MPEG_L3_ENC_PRIVATE *pmpeg = (MPEG_L3_ENC_PRIVATE*) psf->codec_data ;
501 if ((psf->error = mpeg_l3_encoder_construct (psf)))
514 { psf_log_printf (psf, "lame_encode_buffer returned %d\n", nbytes) ;
519 { writen = psf_fwrite (pmpeg->block, 1, nbytes, psf) ;
521 { psf_log_printf (psf, "*** Warning : short write (%d != %d).\n", writen, nbytes) ;
534 mpeg_l3_encode_write_int_mono (SF_PRIVATE *psf, const int *ptr, sf_count_t len)
535 { MPEG_L3_ENC_PRIVATE *pmpeg = (MPEG_L3_ENC_PRIVATE*) psf->codec_data ;
539 if ((psf->error = mpeg_l3_encoder_construct (psf)))
547 { psf_log_printf (psf, "lame_encode_buffer returned %d\n", nbytes) ;
552 { writen = psf_fwrite (pmpeg->block, 1, nbytes, psf) ;
554 { psf_log_printf (psf, "*** Warning : short write (%d != %d).\n", writen, nbytes) ;
567 mpeg_l3_encode_write_int_stereo (SF_PRIVATE *psf, const int *ptr, sf_count_t len)
568 { MPEG_L3_ENC_PRIVATE *pmpeg = (MPEG_L3_ENC_PRIVATE*) psf->codec_data ;
572 if ((psf->error = mpeg_l3_encoder_construct (psf)))
580 { psf_log_printf (psf, "lame_encode_buffer returned %d\n", nbytes) ;
585 { writen = psf_fwrite (pmpeg->block, 1, nbytes, psf) ;
587 { psf_log_printf (psf, "*** Warning : short write (%d != %d).\n", writen, nbytes) ;
600 mpeg_l3_encode_write_float_mono (SF_PRIVATE *psf, const float *ptr, sf_count_t len)
601 { MPEG_L3_ENC_PRIVATE *pmpeg = (MPEG_L3_ENC_PRIVATE*) psf->codec_data ;
605 if ((psf->error = mpeg_l3_encoder_construct (psf)))
611 if (psf->norm_float)
616 { psf_log_printf (psf, "lame_encode_buffer returned %d\n", nbytes) ;
621 { writen = psf_fwrite (pmpeg->block, 1, nbytes, psf) ;
623 { psf_log_printf (psf, "*** Warning : short write (%d != %d).\n", writen, nbytes) ;
644 mpeg_l3_encode_write_float_stereo (SF_PRIVATE *psf, const float *ptr, sf_count_t len)
646 MPEG_L3_ENC_PRIVATE *pmpeg = (MPEG_L3_ENC_PRIVATE*) psf->codec_data ;
650 if ((psf->error = mpeg_l3_encoder_construct (psf)))
657 if (psf->norm_float)
666 { psf_log_printf (psf, "lame_encode_buffer returned %d\n", nbytes) ;
671 { writen = psf_fwrite (pmpeg->block, 1, nbytes, psf) ;
673 { psf_log_printf (psf, "*** Warning : short write (%d != %d).\n", writen, nbytes) ;
694 mpeg_l3_encode_write_double_mono (SF_PRIVATE *psf, const double *ptr, sf_count_t len)
696 MPEG_L3_ENC_PRIVATE *pmpeg = (MPEG_L3_ENC_PRIVATE*) psf->codec_data ;
700 if ((psf->error = mpeg_l3_encoder_construct (psf)))
707 if (psf->norm_double)
716 { psf_log_printf (psf, "lame_encode_buffer returned %d\n", nbytes) ;
721 { writen = psf_fwrite (pmpeg->block, 1, nbytes, psf) ;
723 { psf_log_printf (psf, "*** Warning : short write (%d != %d).\n", writen, nbytes) ;
736 mpeg_l3_encode_write_double_stereo (SF_PRIVATE *psf, const double *ptr, sf_count_t len)
738 MPEG_L3_ENC_PRIVATE *pmpeg = (MPEG_L3_ENC_PRIVATE*) psf->codec_data ;
742 if ((psf->error = mpeg_l3_encoder_construct (psf)))
749 if (psf->norm_double)
758 { psf_log_printf (psf, "lame_encode_buffer returned %d\n", nbytes) ;
763 { writen = psf_fwrite (pmpeg->block, 1, nbytes, psf) ;
765 { psf_log_printf (psf, "*** Warning : short write (%d != %d).\n", writen, nbytes) ;
779 mpeg_l3_encoder_init (SF_PRIVATE *psf, int UNUSED (vbr))
780 { psf_log_printf (psf, "This version of libsndfile was compiled without MPEG Layer 3 encoding support.\n") ;