1
/***************************************************************************
2
player.cpp - description
4
begin : Wed Feb 20 2002
5
copyright : (C) 2002 by Tue and Ken Haste Andersen
7
***************************************************************************/
9
/***************************************************************************
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. *
16
***************************************************************************/
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)
27
qDebug("Player: init...");
30
/* -------- ------------------------------------------------------
31
Purpose: Terminate and deallocate the synthesis system
34
-------- ------------------------------------------------------ */
40
void Player::allocate()
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];
49
void Player::deallocate()
53
delete [] process_buffer;
57
/* -------- ------------------------------------------------------
58
Purpose: Start the audio stream
59
Input: Internal synth datastructure
61
-------- ------------------------------------------------------ */
62
void Player::start(EngineBuffer *_reader) {
65
// Initialize position in readbuffer:
70
/* -------- ------------------------------------------------------
71
Purpose: Internal callback function used for preparing samples
72
for playback. This is where the synthesis is done.
75
-------- ------------------------------------------------------ */
76
int Player::prepareBuffer() {
77
// ----------------------------------------------------
79
// ----------------------------------------------------
81
// Resample; the linear interpolation is done in readfile:
82
reader->process(0, process_buffer, BUFFER_SIZE);
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]);
88
return 0; // Hack. Should only return 0 when not at end of file