Just Intonation  Version 1.3.0 (18)
Explore scale-independent dynamically adapting tuning in just intonation
wave.h
Go to the documentation of this file.
1 /*****************************************************************************
2  * Copyright 2016-2017 Karolin Stange, Christoph Wick, and Haye Hinrichsen
3  *
4  * This file is part of JustIntonation.
5  *
6  * JustIntonation is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by the
8  * Free Software Foundation, either version 3 of the License, or (at your
9  * option) any later version.
10  *
11  * JustIntonation is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14  * for more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with JustIntonation. If not, see http://www.gnu.org/licenses/.
18  *****************************************************************************/
19 
20 //=============================================================================
21 // Wave: Class holding the sampled sound for one key
22 //=============================================================================
23 
24 #ifndef WAVE_H
25 #define WAVE_H
26 
27 #include <QVector>
28 #include <QIODevice>
29 #include <complex>
30 
48 
49 class Wave
50 {
51 public:
52  Wave();
53 
54  //friend class Sampler;
55 
56  bool read (QIODevice &iodevice);
57  bool write (QIODevice &iodevice);
58 
59  bool insert (const QVector<qint32> &L, const QVector<qint32> &R,
60  const bool release, const double amplitude);
61 
62  void printInfo (int keynumber=0);
63 
64  quint32 getRepetitionIndex() { return mRepetitionIndex; }
66  const QVector<qint16>* getSustainSample() { return &mSustainSample; }
67  const QVector<qint16>* getReleaseSample() { return &mReleaseSample; }
68  int getReleaseShift() { return mReleaseShift; }
69  int getSustainShift() { return mSustainShift; }
70 
71  double getEnvelope (int index) { return mEnvelope[index/envelopeWidth]; }
72 
73  bool envelopeExists () { return mEnvelope.size() > 0; }
74  bool waveFormExists () { return mSustainSample.size() > 0; }
75  bool releaseExists () { return mReleaseSample.size() > 0; }
76 
77  void computeTriangularWave(double frequency, int samplerate, double stereo);
78 private:
79  quint32 mRepetitionIndex;
81  QVector<qint16> mSustainSample;
82  QVector<qint16> mReleaseSample;
85  QVector<double> mEnvelope;
86 
87  void computeEnvelope(int samplerate);
89 
90 private:
91  const int maxNumberOfFrames = (1<<20)-2;
92  const int envelopeWidth = 0x1000;
93 };
94 
95 #endif // WAVE_H
quint32 mRepetitionIndex
Index from where on the sample is repeated.
Definition: wave.h:79
bool waveFormExists()
Definition: wave.h:74
Wave()
Constructor, resetting member variables.
Definition: wave.cpp:46
QVector< double > mEnvelope
Amplitude envelope.
Definition: wave.h:85
Class holding the sampled sound for one key.
Definition: wave.h:49
const int maxNumberOfFrames
Maximal number of frames.
Definition: wave.h:91
const QVector< qint16 > * getSustainSample()
Definition: wave.h:66
QVector< qint16 > mSustainSample
Sound sample when key is pressed.
Definition: wave.h:81
const int envelopeWidth
Frames per envelope point.
Definition: wave.h:92
int getReleaseShift()
Definition: wave.h:68
int mReleaseShift
PCM amplitedes shifted # bits to the left.
Definition: wave.h:84
quint32 getRepetitionIndex()
Definition: wave.h:64
double getEnvelope(int index)
Definition: wave.h:71
void printInfo(int keynumber=0)
Debugging function: Write a short summary of the wave data to qDebug()
Definition: wave.cpp:266
bool envelopeExists()
Definition: wave.h:73
void automaticCyclicMorphing()
Function defined externally (Importer)
bool insert(const QVector< qint32 > &L, const QVector< qint32 > &R, const bool release, const double amplitude)
Definition: wave.cpp:95
int getSustainShift()
Definition: wave.h:69
void computeEnvelope(int samplerate)
Determine the envelope of the sustain wave.
Definition: wave.cpp:283
QVector< qint16 > mReleaseSample
Sound sample when key is releasek.
Definition: wave.h:82
bool releaseExists()
Definition: wave.h:75
const QVector< qint16 > * getReleaseSample()
Definition: wave.h:67
bool read(QIODevice &iodevice)
Read a wave from disk.
Definition: wave.cpp:211
bool write(QIODevice &iodevice)
Write a PCM wave to disk (QIODevice)
Definition: wave.cpp:159
void computeTriangularWave(double frequency, int samplerate, double stereo)
Compute a synthetic triangular wave.
Definition: wave.cpp:67
double mRepetitionFactor
Amplitude decrease factor upon repetition.
Definition: wave.h:80
int mSustainShift
PCM amplitudes shifted # bits to the left.
Definition: wave.h:83
double getRepetitionFactor()
Definition: wave.h:65