~ubuntu-branches/ubuntu/hoary/kdemultimedia/hoary

« back to all changes in this revision

Viewing changes to mpeglib/lib/frame/pcmFrame.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Martin Schulze
  • Date: 2003-01-22 15:00:51 UTC
  • Revision ID: james.westby@ubuntu.com-20030122150051-uihwkdoxf15mi1tn
Tags: upstream-2.2.2
ImportĀ upstreamĀ versionĀ 2.2.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
  pcm frame description.
 
3
  Copyright (C) 2001  Martin Vogt
 
4
 
 
5
  This program is free software; you can redistribute it and/or modify
 
6
  it under the terms of the GNU Library General Public License as published by
 
7
  the Free Software Foundation.
 
8
 
 
9
  For more information look at the file COPYRIGHT in this package
 
10
 
 
11
 */
 
12
 
 
13
 
 
14
 
 
15
#include "pcmFrame.h"
 
16
#include <stdlib.h>
 
17
 
 
18
#define convMacro(in,dtemp,tmp)                                              \
 
19
    in[0]*=SCALFACTOR;                                                       \
 
20
    dtemp = ((((65536.0 * 65536.0 * 16)+(65536.0 * 0.5))* 65536.0))+(in[0]); \
 
21
    tmp = ((*(int *)&dtemp) - 0x80000000);                                   \
 
22
    in++;                                                                    \
 
23
    if(tmp>32767) {                                                          \
 
24
      tmp=32767;                                                             \
 
25
    } else if (tmp<-32768) {                                                 \
 
26
      tmp =-0x8000;                                                          \
 
27
    }                                                                        
 
28
 
 
29
 
 
30
 
 
31
PCMFrame::PCMFrame(int size) {
 
32
  data=new short int[size];
 
33
  len=0;
 
34
  this->size=size;
 
35
  // this format has a sampleSize of 16, signed, endian==machine
 
36
  this->sampleSize=sizeof(short int)*8;
 
37
  this->lSigned=true;
 
38
  this->lBigEndian=AUDIOFRAME_BIGENDIAN;
 
39
  setFrameType(_FRAME_AUDIO_PCM);
 
40
}
 
41
 
 
42
 
 
43
PCMFrame::~PCMFrame() {
 
44
  delete data;
 
45
}
 
46
 
 
47
 
 
48
void PCMFrame::putFloatData(float* left,float* right,int copyLen) {
 
49
  int destSize=0;
 
50
  if (left  != NULL) destSize++;
 
51
  if (right != NULL) destSize++;
 
52
  destSize*=copyLen;
 
53
  if ((len+destSize) > size) {
 
54
    cout << "cannot copy putFloatData L/R version . Does not fit"<<endl;
 
55
    exit(0);
 
56
  }
 
57
  double dtemp; 
 
58
  int tmp;
 
59
  int i=copyLen;
 
60
  switch(getStereo()) {
 
61
  case 1:
 
62
    while(i > 0) {
 
63
      convMacro(left,dtemp,tmp);
 
64
      data[len++]=(short int)tmp;
 
65
      convMacro(right,dtemp,tmp);
 
66
      data[len++]=(short int)tmp;
 
67
      i--;
 
68
    } 
 
69
    break;
 
70
  case 0:
 
71
    if (left != NULL) {
 
72
      int i=copyLen;
 
73
      while(i > 0) {
 
74
        convMacro(left,dtemp,tmp);
 
75
        data[len++]=(short int)tmp;
 
76
        i--;
 
77
        // right channel empty
 
78
        len++;
 
79
      } 
 
80
    }
 
81
    if (right != NULL) {
 
82
      int i=copyLen;
 
83
      len=len-destSize;
 
84
      while(i > 0) {
 
85
        // select right channel
 
86
        len++;
 
87
        convMacro(right,dtemp,tmp);
 
88
        data[len++]=(short int)tmp;
 
89
        i--;
 
90
        // left channel already copied
 
91
      }  
 
92
    }
 
93
  default:
 
94
    cout << "unknown stereo value in pcmFrame"<<endl;
 
95
    exit(0);
 
96
  }
 
97
}
 
98
 
 
99
void PCMFrame::putFloatData(float* in,int lenCopy) {
 
100
 
 
101
  if ((len+lenCopy) > size) {
 
102
    cout << "cannot copy putFloatData. Does not fit"<<endl;
 
103
    exit(0);
 
104
  }
 
105
  double dtemp; 
 
106
  int tmp;
 
107
  while(lenCopy > 0) {
 
108
    convMacro(in,dtemp,tmp);
 
109
    data[len++]=(short int)tmp;
 
110
    lenCopy--;
 
111
  }
 
112
 
 
113
}
 
114
 
 
115
 
 
116