Re: [Rhythmbox-devel] playlist source burner
- From: Bastien Nocera <hadess hadess net>
- To: mccann jhu edu
- Cc: rhythmbox-devel gnome org, Colin Walters <walters verbum org>
- Subject: Re: [Rhythmbox-devel] playlist source burner
- Date: Sun, 29 Aug 2004 22:16:11 +0100
Replying to myself
On Sun, 2004-08-29 at 17:08 +0100, Bastien Nocera wrote:
> > The next thing is to determine how much space will be needed. The
> > easiest way is to compute it from the song duration. Is it safe to rely
> > on the duration being present and correct?
>
> And then verify that the .wav files created still fit on the CD.
Some code I had around that does that.
Code is GPL, BTW.
---
Bastien Nocera <hadess hadess net>
I have just watched The Big Blue on video but I couldn't see the
porpoise. -- reader Nibs Swenior
#include <glib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
#include "acb-wave.h"
#define WAV_SIGNATURE_SIZE 16
#define LPCM_BITRATE (16 * 44.100 * 2)
/* From xine-lib, whoop */
typedef struct __attribute__((__packed__)) {
gint16 wFormatTag;
gint16 nChannels;
gint32 nSamplesPerSec;
gint32 nAvgBytesPerSec;
gint16 nBlockAlign;
gint16 wBitsPerSample;
gint16 cbSize;
} waveformat;
#ifndef ATTRIBUTE_PACKED
#pragma pack()
#endif
/* Data from
* http://www.onicos.com/staff/iz/formats/wav.html
*/
gint64
acb_wave_time (const char *filename)
{
char buffer[WAV_SIGNATURE_SIZE];
int fd, len;
waveformat *wav;
fd = open (filename, 0);
if (fd < 0)
return ACB_ERROR_OPEN;
if (read (fd, buffer, WAV_SIGNATURE_SIZE) != WAV_SIGNATURE_SIZE)
return ACB_ERROR_NOT_WAVE_TOO_SMALL;
if ((buffer[0] != 'R') ||
(buffer[1] != 'I') ||
(buffer[2] != 'F') ||
(buffer[3] != 'F') ||
(buffer[8] != 'W') ||
(buffer[9] != 'A') ||
(buffer[10] != 'V') ||
(buffer[11] != 'E') ||
(buffer[12] != 'f') ||
(buffer[13] != 'm') ||
(buffer[14] != 't') ||
(buffer[15] != ' '))
return -1;
if (read (fd, &len, sizeof(len)) != sizeof (len))
{
close (fd);
return ACB_ERROR_NOT_WAVE_TOO_SMALL;
}
if (GINT_TO_LE (len) != 16)
{
close (fd);
g_print ("file len not defined\n");
return ACB_ERROR_NOT_WAVE_FORMAT;
}
wav = g_malloc (len);
if (read (fd, wav, len) != len)
{
g_free (wav);
close (fd);
return ACB_ERROR_NOT_WAVE_FILE;
}
close (fd);
if (wav->nChannels != 2
|| wav->nSamplesPerSec != 44100
|| wav->wBitsPerSample != 16)
{
g_free (wav);
return ACB_ERROR_NOT_WAVE_FORMAT;
}
g_free (wav);
{
struct stat buf;
if (stat (filename, &buf) != 0)
return ACB_ERROR_OPEN;
return buf.st_size * 8 / LPCM_BITRATE;
}
}
#define ACB_ERROR_OPEN -1
#define ACB_ERROR_NOT_WAVE_TOO_SMALL -2
#define ACB_ERROR_NOT_WAVE_FILE -3
#define ACB_ERROR_NOT_WAVE_FORMAT -4
gint64 acb_wave_time (const char *filename);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]