~mixxxdevelopers/mixxx/features_library_scanner

« back to all changes in this revision

Viewing changes to mixxx/mixxx/player.cpp

  • Committer: tuehaste
  • Date: 2002-02-26 11:12:07 UTC
  • Revision ID: vcs-imports@canonical.com-20020226111207-5rly26cj9gdd19ba
Initial revision

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
                          player.cpp  -  description
 
3
                             -------------------
 
4
    begin                : Wed Feb 20 2002
 
5
    copyright            : (C) 2002 by Tue and Ken Haste Andersen
 
6
    email                : 
 
7
 ***************************************************************************/
 
8
 
 
9
/***************************************************************************
 
10
 *                                                                         *
 
11
 *   This program is free software; you can redistribute it and/or modify  *
 
12
 *   it under the terms of the GNU General Public License as published by  *
 
13
 *   the Free Software Foundation; either version 2 of the License, or     *
 
14
 *   (at your option) any later version.                                   *
 
15
 *                                                                         *
 
16
 ***************************************************************************/
 
17
 
 
18
#include "player.h"
 
19
 
 
20
/* -------- ------------------------------------------------------
 
21
   Purpose: Initializes the audio hardware.
 
22
   Input:   Size of the output buffer in samples
 
23
   Output:  Pointer to internal synthesis data structure.
 
24
   -------- ------------------------------------------------------ */
 
25
Player::Player(int size)
 
26
{
 
27
        qDebug("Player: init...");
 
28
}
 
29
 
 
30
/* -------- ------------------------------------------------------
 
31
   Purpose: Terminate and deallocate the synthesis system
 
32
   Input:   -
 
33
   Output:  -
 
34
   -------- ------------------------------------------------------ */
 
35
Player::~Player()
 
36
{
 
37
        deallocate();
 
38
}
 
39
 
 
40
void Player::allocate()
 
41
{
 
42
        // Allocate buffers
 
43
        out_buffer = new SAMPLE[BUFFER_SIZE];
 
44
        process_buffer = new CSAMPLE[BUFFER_SIZE];
 
45
        tmp1 = new CSAMPLE[BUFFER_SIZE];
 
46
        tmp2 = new CSAMPLE[BUFFER_SIZE];
 
47
}
 
48
 
 
49
void Player::deallocate()
 
50
{
 
51
        delete [] tmp2;
 
52
        delete [] tmp1;
 
53
        delete [] process_buffer;
 
54
        delete [] out_buffer;
 
55
}
 
56
 
 
57
/* -------- ------------------------------------------------------
 
58
   Purpose: Start the audio stream
 
59
   Input:   Internal synth datastructure
 
60
   Output:
 
61
   -------- ------------------------------------------------------ */
 
62
void Player::start(EngineBuffer *_reader) {
 
63
        reader = _reader;
 
64
 
 
65
        // Initialize position in readbuffer:
 
66
        play_pos = 0;
 
67
}
 
68
 
 
69
 
 
70
/* -------- ------------------------------------------------------
 
71
   Purpose: Internal callback function used for preparing samples
 
72
            for playback. This is where the synthesis is done.
 
73
   Input:   -
 
74
   Output:  -
 
75
   -------- ------------------------------------------------------ */
 
76
int Player::prepareBuffer() {
 
77
  // ----------------------------------------------------
 
78
  // Do the processing.
 
79
  // ----------------------------------------------------
 
80
 
 
81
  // Resample; the linear interpolation is done in readfile:
 
82
  reader->process(0, process_buffer, BUFFER_SIZE);
 
83
 
 
84
  // Convert the signal back to SAMPLE and write to the sound cards buffer:
 
85
  for (int i=0; i<BUFFER_SIZE; i++)
 
86
    out_buffer[i] = (SAMPLE)(0.5*process_buffer[i]);
 
87
 
 
88
  return 0; // Hack. Should only return 0 when not at end of file
 
89
}