1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
|
/*
* audacitylabel.c -- Audacity label file parser portion of the Mp3Splt utility
* Utility for mp3/ogg splitting without decoding
*
* Copyright (c) 2002-2004 M. Trotta - <matteo.trotta@lib.unimib.it>
* Copyright (c) 2007 Federico Grau - <donfede@casagrau.org>
*
* http://mp3splt.sourceforge.net
* http://audacity.sourceforge.net/
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <ctype.h>
#include <netdb.h>
#include <sys/types.h>
#include <math.h>
#ifndef NO_OGG
#include <ogg/ogg.h>
#include <vorbis/codec.h>
#include <vorbis/vorbisfile.h>
#endif
#include "mp3.h"
#include "ogg.h"
#include "splt.h"
#include "mp3splt.h"
#include "cddb.h"
int get_audacitylabel_splitpoints(unsigned char *file, splt_state *state)
{
FILE *file_input;
char line[512];
double label_start;
double label_end;
char *label_name = NULL;
char *last_label_name = NULL;
int i;
int tracks = -1;
char *ptr = NULL;;
if (!(file_input=fopen(file, "r"))) {
perror(file);
exit(1);
}
fseek (file_input, 0, SEEK_SET);
while (fgets(line, 512, file_input)!=NULL)
{
ptr = line;
errno = 0;
label_start = strtod(ptr, &ptr);
if (errno != 0) return -1;
label_end = strtod(ptr, &ptr);
if (errno != 0) return -1;
// FIXME: how to handle if label_start != label_end?
// Trim off whitespace before the name.
while (isspace(*ptr)) {
ptr++;
}
// Trim off whitespace after the name.
i = strlen(ptr) - 1;
while (isspace(ptr[i])) {
ptr[i] = '\0';
i--;
}
if ( (last_label_name == NULL) && (label_name != NULL) ) {
last_label_name = strndup(label_name, 255);
free(label_name);
label_name = NULL;
}
label_name = strndup(ptr, 255);
cleanstring(label_name);
tracks++;
state->splitpoints[tracks] = floorf(label_start);
label_start = (label_start - state->splitpoints[tracks])*4/3; // FIXME: what/why is this...
state->splitpoints[tracks] += label_start;
if (tracks > 0) {
strncpy(state->fn[tracks], last_label_name, 256);
free(last_label_name);
last_label_name = NULL;
}
} // end while fgets line
if (tracks>0) {
tracks++;
state->splitpoints[tracks] = (float) -1.f; // End of file
strncpy(state->fn[tracks], label_name, 256);
free(label_name);
}
fclose(file_input);
return tracks;
}
|