comparison audioio/ClipMixer.h @ 450:d9d132c0e240 alignment_view

Merge from default branch
author Chris Cannam
date Mon, 20 Apr 2015 09:21:32 +0100
parents 72c662fe7ea3
children
comparison
equal deleted inserted replaced
430:adfb2948fabf 450:d9d132c0e240
17 #define CLIP_MIXER_H 17 #define CLIP_MIXER_H
18 18
19 #include <QString> 19 #include <QString>
20 #include <vector> 20 #include <vector>
21 21
22 #include "base/BaseTypes.h"
23
22 /** 24 /**
23 * Mix in synthetic notes produced by resampling a prerecorded 25 * Mix in synthetic notes produced by resampling a prerecorded
24 * clip. (i.e. this is an implementation of a digital sampler in the 26 * clip. (i.e. this is an implementation of a digital sampler in the
25 * musician's sense.) This can mix any number of notes of arbitrary 27 * musician's sense.) This can mix any number of notes of arbitrary
26 * frequency, so long as they all use the same sample clip. 28 * frequency, so long as they all use the same sample clip.
27 */ 29 */
28 30
29 class ClipMixer 31 class ClipMixer
30 { 32 {
31 public: 33 public:
32 ClipMixer(int channels, int sampleRate, int blockSize); 34 ClipMixer(int channels, sv_samplerate_t sampleRate, sv_frame_t blockSize);
33 ~ClipMixer(); 35 ~ClipMixer();
34 36
35 void setChannelCount(int channels); 37 void setChannelCount(int channels);
36 38
37 /** 39 /**
39 * construct a new ClipMixer if you want a different clip. The 41 * construct a new ClipMixer if you want a different clip. The
40 * clip was recorded at a pitch with fundamental frequency clipF0, 42 * clip was recorded at a pitch with fundamental frequency clipF0,
41 * and should be scaled by level (in the range 0-1) when playing 43 * and should be scaled by level (in the range 0-1) when playing
42 * back. 44 * back.
43 */ 45 */
44 bool loadClipData(QString clipFilePath, float clipF0, float level); 46 bool loadClipData(QString clipFilePath, double clipF0, double level);
45 47
46 void reset(); // discarding any playing notes 48 void reset(); // discarding any playing notes
47 49
48 struct NoteStart { 50 struct NoteStart {
49 int frameOffset; // within current processing block 51 sv_frame_t frameOffset; // within current processing block
50 float frequency; // Hz 52 float frequency; // Hz
51 float level; // volume in range (0,1] 53 float level; // volume in range (0,1]
52 float pan; // range [-1,1] 54 float pan; // range [-1,1]
53 }; 55 };
54 56
55 struct NoteEnd { 57 struct NoteEnd {
56 int frameOffset; // in current processing block 58 sv_frame_t frameOffset; // in current processing block
57 float frequency; // matching note start 59 float frequency; // matching note start
58 }; 60 };
59 61
60 void mix(float **toBuffers, 62 void mix(float **toBuffers,
61 float gain, 63 float gain,
62 std::vector<NoteStart> newNotes, 64 std::vector<NoteStart> newNotes,
63 std::vector<NoteEnd> endingNotes); 65 std::vector<NoteEnd> endingNotes);
64 66
65 private: 67 private:
66 int m_channels; 68 int m_channels;
67 int m_sampleRate; 69 sv_samplerate_t m_sampleRate;
68 int m_blockSize; 70 sv_frame_t m_blockSize;
69 71
70 QString m_clipPath; 72 QString m_clipPath;
71 73
72 float *m_clipData; 74 float *m_clipData;
73 int m_clipLength; 75 sv_frame_t m_clipLength;
74 float m_clipF0; 76 double m_clipF0;
75 float m_clipRate; 77 sv_samplerate_t m_clipRate;
76 78
77 std::vector<NoteStart> m_playing; 79 std::vector<NoteStart> m_playing;
78 80
79 float getResampleRatioFor(float frequency); 81 double getResampleRatioFor(double frequency);
80 int getResampledClipDuration(float frequency); 82 sv_frame_t getResampledClipDuration(double frequency);
81 83
82 void mixNote(float **toBuffers, 84 void mixNote(float **toBuffers,
83 float *levels, 85 float *levels,
84 float frequency, 86 float frequency,
85 int sourceOffset, // within resampled note 87 sv_frame_t sourceOffset, // within resampled note
86 int targetOffset, // within target buffer 88 sv_frame_t targetOffset, // within target buffer
87 int sampleCount, 89 sv_frame_t sampleCount,
88 bool isEnd); 90 bool isEnd);
89 }; 91 };
90 92
91 93
92 #endif 94 #endif