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 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156
|
// File_readSndInt.cpp Generated from make and File_readSndShort.cpp
#define TYPE_INT
/* Copyright (c) 1998, 1999, 2003, 2004 Lance Arsenault, (GNU GPL (v2+))
*/
#include "config.h"
#ifdef USE_LIBSNDFILE
#include <iostream>
#ifdef QP_ARCH_DARWIN
# include <limits.h>
# include <float.h>
#else
# include <values.h>
#endif
#include <list>
#include <iomanip>
#include <sndfile.h>
#include <gtkmm.h>
using namespace Gtk;
#include "errorStr.h"
#include "value_t.h"
#include "Field.h"
#include "Plot.h"
#include "ColorGen.h"
#include "Graph.h"
#include "PlotSelector.h"
#include "ValueSlider.h"
#include "PlotLister.h"
#include "PlotConfig.h"
#include "GraphConfig.h"
#include "Globel.h"
#include "MainMenuBar.h"
#include "ButtonBar.h"
#include "StatusBar.h"
#include "MainWindow.h"
#include "App.h"
#include "Source.h"
#include "FileList.h"
#include "File.h"
#include "errorStr.h"
#include "ArrayField.h"
#include "LinearField.h"
#ifdef TYPE_INT
# define TYPE int
# define readSndTYPE readSndInt
# define readFunc sf_readf_int
#endif
#ifdef TYPE_FLOAT
# define TYPE float
# define readSndTYPE readSndFloat
# define readFunc sf_readf_float
#endif
#ifdef TYPE_DOUBLE
# define TYPE double
# define readSndTYPE readSndDouble
# define readFunc sf_readf_double
#endif
// The default case is TYPE short
#if (!defined TYPE_INT &&\
!defined TYPE_FLOAT &&\
!defined TYPE_DOUBLE)
# define TYPE short
# define readSndTYPE readSndShort
# define readFunc sf_readf_short
#endif
// C++ Templates will not make methods with templates without making
// the whole class a template. I did not want to make the class File a
// template, that would be lots more work than this. So I generate
// the code from this file for the following 4 methods:
// by default File::readSndShort()
// by defining TYPE_INT File::readSndInt()
// by defining TYPE_FLOAT File::readSndFloat()
// by defining TYPE_DOUBLE File::readSndDouble()
void File::
readSndTYPE(::SNDFILE *sndfile, int samplerate,
count_t numberOfValues, int channels,
const FileList *fileList)
{
ArrayField<TYPE> **field =
static_cast<ArrayField<TYPE> **>
(malloc(sizeof(ArrayField<TYPE> *)*channels));
TYPE *data = static_cast<TYPE *>(malloc(sizeof(TYPE)*channels));
int i;
count_t j=0;
error = 0;
// get the fields
for(i=0;i<channels;i++)
{
field[i] = new ArrayField<TYPE>(this, numberOfValues);
if(error)
{
int k;
for(k=0;k<=i;k++)
delete field[k];
goto cleanup;
}
}
{
// add a linear field and add fields to the list
Field *lField = new LinearField(this, 1.0/((value_t) samplerate));
// Make this LinearField first in the list.
remove(lField);
push_front(lField);
lField->setName("seconds");
lField->setLabel("time");
}
for(i=0;i<channels;i++)
{
char str[16];
sprintf(str, "%d", i+1);
field[i]->setName(str);
field[i]->setLabel("channel");
}
// read the data and put it in the field
for(;j<numberOfValues;j++)
{
if(1 != readFunc(sndfile, data, 1))
{
error = 1;
snprintf(errorStr, ERRORSTR_LENGTH,
"error using libsndfile: %s", sf_strerror(sndfile));
break;
}
for(i=0;i<channels;i++)
field[i]->write(data[i]);
}
cleanup:
free(data);
free(field);
}
#endif // #ifdef USE_LIBSNDFILE
|