Beispiel #1
0
int wav_open(auds_t *auds, char *fname)
{
	wav_t *wav=malloc(sizeof(wav_t));
	if(!wav) return -1;
	memset(wav,0,sizeof(wav_t));
	auds->stream=(void *)wav;
	wav->inf=fopen(fname,"r");
	if(!wav->inf) goto erexit;
	if(read_wave_header(wav, &auds->sample_rate, &auds->channels)==-1) goto erexit;
	auds->chunk_size=aud_clac_chunk_size(auds->sample_rate);
	wav->buffer=(__u8 *)malloc(MAX_SAMPLES_IN_CHUNK*4+16);
	if(!wav->buffer) goto erexit;
	return 0;
 erexit:
	wav_close(auds);
	return -1;
}
Beispiel #2
0
static gboolean
xmms_wave_init (xmms_xform_t *xform)
{
	xmms_wave_data_t *data;
	xmms_error_t error;
	xmms_sample_format_t sample_fmt;
	xmms_wave_format_t fmt;
	guint8 buf[1024];
	gint read;

	g_return_val_if_fail (xform, FALSE);

	data = g_new0 (xmms_wave_data_t, 1);
	g_return_val_if_fail (data, FALSE);

	xmms_xform_private_data_set (xform, data);

	read = xmms_xform_peek (xform, (gchar *) buf, sizeof (buf), &error);

	if (read < WAVE_HEADER_MIN_SIZE) {
		xmms_log_error ("Could not read wave header");
		return FALSE;
	}

	fmt = read_wave_header (data, buf, read);

	switch (fmt) {
		case WAVE_FORMAT_UNDEFINED:
			xmms_log_error ("Not a valid Wave stream");
			return FALSE;
		case WAVE_FORMAT_MP3:
			xmms_xform_outdata_type_add (xform,
			                             XMMS_STREAM_TYPE_MIMETYPE,
			                             "audio/mpeg",
			                             XMMS_STREAM_TYPE_END);
			break;
		case WAVE_FORMAT_PCM:
			xmms_wave_get_media_info (xform);

			if (read < data->header_size) {
				xmms_log_info ("Wave header too big?");
				return FALSE;
			}
			/* skip over the header */
			xmms_xform_read (xform, (gchar *) buf, data->header_size, &error);

			sample_fmt = (data->bits_per_sample == 8 ? XMMS_SAMPLE_FORMAT_U8
			                                         : XMMS_SAMPLE_FORMAT_S16);

			xmms_xform_outdata_type_add (xform,
			                             XMMS_STREAM_TYPE_MIMETYPE,
			                             "audio/pcm",
			                             XMMS_STREAM_TYPE_FMT_FORMAT,
			                             sample_fmt,
			                             XMMS_STREAM_TYPE_FMT_CHANNELS,
			                             data->channels,
			                             XMMS_STREAM_TYPE_FMT_SAMPLERATE,
			                             data->samplerate,
			                             XMMS_STREAM_TYPE_END);
	}

	return TRUE;
}
Beispiel #3
0
int wav_open(auds_t *auds, char *fname)
{
        struct stat finfo;
	wav_t *wav=malloc(sizeof(wav_t));
	if(!wav) return -1;
	memset(wav,0,sizeof(wav_t));
	auds->stream=(void *)wav;
	wav->inf=fopen(fname,"r");
	if(!wav->inf) goto erexit;
        if ( csync!=0 )
        {
	   wav->inf2=fopen(fname,"r");
	   if(!wav->inf2) goto erexit;
        }
	if(read_wave_header(wav, &auds->sample_rate, &auds->channels)==-1) goto erexit;
	auds->chunk_size=aud_clac_chunk_size(auds->sample_rate);
	wav->buffer=(uint8_t *)malloc(MAX_SAMPLES_IN_CHUNK*4+16);
	if(!wav->buffer) goto erexit;

        if(stat(fname,&finfo)<0)
        {
          ERRMSG( "Couldn't get file size\n" );
          fduration=0;
        }
        else
        {
          fduration=(finfo.st_size-sizeof(wave_header_t))/(sizeof(short)*auds->channels*auds->sample_rate);
          flength=(finfo.st_size-sizeof(wave_header_t))/(sizeof(short)*auds->channels);
          DBGMSG( "duration in seconds : %d\n", fduration );
        }

        DBGMSG( "Start time is %ld\n", startinms );
        if ( startinms != -1 )
        {
           long nbbytes = sizeof(short)*auds->channels*auds->sample_rate;
           nbbytes *= startinms/1000;
           DBGMSG( "inf : Seeking to %ld bytes\n", nbbytes );

           if ( fseek( wav->inf, nbbytes, SEEK_CUR ) < 0 )
           {
              ERRMSG( "Couldn't seek specified start time : %s", strerror( errno ) );
              wav_close(auds);
              return -1;
           }

           if ( csync!=0 )
           {
              nbbytes = sizeof(short)*auds->channels*auds->sample_rate;
              int mcsync = (int)(csync*1000.0);
              nbbytes *= (startinms+mcsync)/1000;
              DBGMSG( "inf2 : seeking to %ld from current\n", nbbytes );

              if ( fseek( wav->inf2, nbbytes, SEEK_CUR ) < 0 )
              {
                 ERRMSG( "Couldn't seek specified start time : %s", strerror( errno ) );
                 wav_close(auds);
                 return -1;
              }
           }
        }
        else
        {
           if ( csync!=0 )
           {
              int nbbytes = sizeof(short)*auds->channels*auds->sample_rate;
              int mcsync = (int)(csync*1000.0);
              nbbytes *= mcsync/1000;
              DBGMSG( "inf2 : seeking to %d from current\n", nbbytes );
              if ( fseek( wav->inf2, nbbytes, SEEK_CUR ) < 0 )
              {
                 ERRMSG( "fseek ahead failed : reason : %s", strerror( errno ) );
                 goto erexit;
              }
           }
        }

	return 0;
 erexit:
	wav_close(auds);
	return -1;
}