kwave  18.07.70
VorbisDecoder.cpp File Reference
#include "config.h"
#include <stdlib.h>
#include <ogg/ogg.h>
#include <vorbis/codec.h>
#include <QDate>
#include <QIODevice>
#include <QString>
#include <KLocalizedString>
#include "libkwave/Compression.h"
#include "libkwave/MessageBox.h"
#include "libkwave/MultiWriter.h"
#include "libkwave/Sample.h"
#include "libkwave/SampleArray.h"
#include "libkwave/StandardBitrates.h"
#include "libkwave/Utils.h"
#include "VorbisDecoder.h"
Include dependency graph for VorbisDecoder.cpp:

Go to the source code of this file.

Macros

#define DEFAULT_BITRATE   128000
 

Functions

static int decodeFrame (float **pcm, unsigned int size, Kwave::MultiWriter &dest)
 

Macro Definition Documentation

◆ DEFAULT_BITRATE

#define DEFAULT_BITRATE   128000

bitrate to be used when no bitrate has been decoded

Definition at line 42 of file VorbisDecoder.cpp.

Referenced by Kwave::VorbisDecoder::close(), and Kwave::VorbisDecoder::open().

Function Documentation

◆ decodeFrame()

static int decodeFrame ( float **  pcm,
unsigned int  size,
Kwave::MultiWriter dest 
)
inlinestatic

Definition at line 234 of file VorbisDecoder.cpp.

References double2sample(), SAMPLE_MAX, SAMPLE_MIN, and Kwave::MultiTrackSink< SINK, INITIALIZE >::tracks().

Referenced by Kwave::VorbisDecoder::decode().

236 {
237  const unsigned int tracks = dest.tracks();
238 
239  // convert floats to 16 bit signed ints
240  // (host order) and interleave
241  for (unsigned int track = 0; track < tracks; track++) {
242  float *mono = pcm[track];
243  int bout = size;
244  unsigned int ofs = 0;
245  Kwave::SampleArray buffer(size);
246 
247  while (bout--) {
248  // scale, use some primitive noise shaping + clipping
249  double noise = (drand48() - double(0.5)) / double(SAMPLE_MAX);
250  double d = static_cast<double>(*(mono++));
251  sample_t s = qBound<sample_t>(
252  SAMPLE_MIN, double2sample(d + noise), SAMPLE_MAX
253  );
254 
255  // write the clipped sample to the stream
256  buffer[ofs++] = s;
257  }
258 
259  // write the buffer to the stream
260  *(dest[track]) << buffer;
261  }
262 
263  return size;
264 }
virtual unsigned int tracks() const Q_DECL_OVERRIDE
#define SAMPLE_MIN
Definition: Sample.h:49
static sample_t double2sample(const double f)
Definition: Sample.h:81
#define SAMPLE_MAX
Definition: Sample.h:52
qint32 sample_t
Definition: Sample.h:37
Here is the call graph for this function:
Here is the caller graph for this function: