kwave  18.07.70
MP3Decoder.cpp File Reference
#include "config.h"
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <id3/globals.h>
#include <id3/misc_support.h>
#include <id3/tag.h>
#include <QDate>
#include <QDateTime>
#include <QLatin1Char>
#include <QTime>
#include "libkwave/Compression.h"
#include "libkwave/GenreType.h"
#include "libkwave/MessageBox.h"
#include "libkwave/MultiWriter.h"
#include "libkwave/Sample.h"
#include "libkwave/SampleArray.h"
#include "libkwave/String.h"
#include "libkwave/Utils.h"
#include "libkwave/Writer.h"
#include "ID3_QIODeviceReader.h"
#include "MP3CodecPlugin.h"
#include "MP3Decoder.h"
Include dependency graph for MP3Decoder.cpp:

Go to the source code of this file.

Classes

struct  Kwave::audio_dither
 

Namespaces

 Kwave
 

Functions

static enum mad_flow _input_adapter (void *data, struct mad_stream *stream)
 
static enum mad_flow _output_adapter (void *data, struct mad_header const *header, struct mad_pcm *pcm)
 
static enum mad_flow _error_adapter (void *data, struct mad_stream *stream, struct mad_frame *frame)
 
static quint32 prng (quint32 state)
 
static qint32 audio_linear_dither (unsigned int bits, mad_fixed_t sample, Kwave::audio_dither *dither)
 

Function Documentation

◆ _error_adapter()

static enum mad_flow _error_adapter ( void *  data,
struct mad_stream *  stream,
struct mad_frame *  frame 
)
static

Definition at line 493 of file MP3Decoder.cpp.

References Kwave::MP3Decoder::handleError().

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

495 {
496  Kwave::MP3Decoder *decoder = reinterpret_cast<Kwave::MP3Decoder *>(data);
497  Q_ASSERT(decoder);
498  return (decoder) ?
499  decoder->handleError(data, stream, frame) : MAD_FLOW_BREAK;
500 }
enum mad_flow handleError(void *data, struct mad_stream *stream, struct mad_frame *frame)
Definition: MP3Decoder.cpp:503
Here is the call graph for this function:
Here is the caller graph for this function:

◆ _input_adapter()

static enum mad_flow _input_adapter ( void *  data,
struct mad_stream *  stream 
)
static

Definition at line 474 of file MP3Decoder.cpp.

References Kwave::MP3Decoder::fillInput().

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

475 {
476  Kwave::MP3Decoder *decoder = reinterpret_cast<Kwave::MP3Decoder *>(data);
477  Q_ASSERT(decoder);
478  return (decoder) ? decoder->fillInput(stream) : MAD_FLOW_STOP;
479 }
enum mad_flow fillInput(struct mad_stream *stream)
Definition: MP3Decoder.cpp:566
Here is the call graph for this function:
Here is the caller graph for this function:

◆ _output_adapter()

static enum mad_flow _output_adapter ( void *  data,
struct mad_header const *  header,
struct mad_pcm *  pcm 
)
static

Definition at line 482 of file MP3Decoder.cpp.

References Kwave::MP3Decoder::processOutput().

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

485 {
486  Kwave::MP3Decoder *decoder = reinterpret_cast<Kwave::MP3Decoder *>(data);
487  Q_ASSERT(decoder);
488  return (decoder) ?
489  decoder->processOutput(data, header, pcm) : MAD_FLOW_STOP;
490 }
enum mad_flow processOutput(void *data, struct mad_header const *header, struct mad_pcm *pcm)
Definition: MP3Decoder.cpp:675
Here is the call graph for this function:
Here is the caller graph for this function:

◆ audio_linear_dither()

static qint32 audio_linear_dither ( unsigned int  bits,
mad_fixed_t  sample,
Kwave::audio_dither dither 
)
inlinestatic

generic linear sample quantize and dither routine (copied from mpg231, mad.c)

Author
Rob Leslie

Definition at line 626 of file MP3Decoder.cpp.

References Kwave::audio_dither::error, prng(), and Kwave::audio_dither::random.

Referenced by Kwave::MP3Decoder::processOutput().

628 {
629  unsigned int scalebits;
630  mad_fixed_t output, mask, random;
631 
632  enum {
633  MIN = -MAD_F_ONE,
634  MAX = MAD_F_ONE - 1
635  };
636 
637  /* noise shape */
638  sample += dither->error[0] - dither->error[1] + dither->error[2];
639 
640  dither->error[2] = dither->error[1];
641  dither->error[1] = dither->error[0] / 2;
642 
643  /* bias */
644  output = sample + mad_fixed_t(1L << (MAD_F_FRACBITS + 1 - bits - 1));
645 
646  scalebits = MAD_F_FRACBITS + 1 - bits;
647  mask = mad_fixed_t(1L << scalebits) - 1;
648 
649  /* dither */
650  random = static_cast<mad_fixed_t>(prng(dither->random));
651  output += (random & mask) - (dither->random & mask);
652 
653  dither->random = random;
654 
655  /* clip */
656  if (output > MAX) {
657  output = MAX;
658  if (sample > MAX) sample = MAX;
659  } else if (output < MIN) {
660  output = MIN;
661  if (sample < MIN) sample = MIN;
662  }
663 
664  /* quantize */
665  output &= ~mask;
666 
667  /* error feedback */
668  dither->error[0] = sample - output;
669 
670  /* scale */
671  return output >> scalebits;
672 }
mad_fixed_t random
Definition: MP3Decoder.cpp:607
static quint32 prng(quint32 state)
Definition: MP3Decoder.cpp:616
mad_fixed_t error[3]
Definition: MP3Decoder.cpp:606
Here is the call graph for this function:
Here is the caller graph for this function:

◆ prng()

static quint32 prng ( quint32  state)
inlinestatic

32-bit pseudo-random number generator (copied from mpg231, mad.c)

Author
Rob Leslie

Definition at line 616 of file MP3Decoder.cpp.

Referenced by audio_linear_dither().

617 {
618  return (state * 0x0019660dL + 0x3c6ef35fL) & 0xffffffffL;
619 }
Here is the caller graph for this function: