Mercurial > hg > svapp
comparison audio/ClipMixer.h @ 482:01669adb0956 tony-2.0-integration
Merge through to branch for Tony 2.0
author | Chris Cannam |
---|---|
date | Thu, 20 Aug 2015 14:54:21 +0100 |
parents | 56acd9368532 |
children | b23bebfdfaba |
comparison
equal
deleted
inserted
replaced
448:b36042cb972a | 482:01669adb0956 |
---|---|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ | |
2 | |
3 /* | |
4 Sonic Visualiser | |
5 An audio file viewer and annotation editor. | |
6 Centre for Digital Music, Queen Mary, University of London. | |
7 This file copyright 2006 Chris Cannam, 2006-2014 QMUL. | |
8 | |
9 This program is free software; you can redistribute it and/or | |
10 modify it under the terms of the GNU General Public License as | |
11 published by the Free Software Foundation; either version 2 of the | |
12 License, or (at your option) any later version. See the file | |
13 COPYING included with this distribution for more information. | |
14 */ | |
15 | |
16 #ifndef CLIP_MIXER_H | |
17 #define CLIP_MIXER_H | |
18 | |
19 #include <QString> | |
20 #include <vector> | |
21 | |
22 #include "base/BaseTypes.h" | |
23 | |
24 /** | |
25 * Mix in synthetic notes produced by resampling a prerecorded | |
26 * clip. (i.e. this is an implementation of a digital sampler in the | |
27 * musician's sense.) This can mix any number of notes of arbitrary | |
28 * frequency, so long as they all use the same sample clip. | |
29 */ | |
30 | |
31 class ClipMixer | |
32 { | |
33 public: | |
34 ClipMixer(int channels, sv_samplerate_t sampleRate, sv_frame_t blockSize); | |
35 ~ClipMixer(); | |
36 | |
37 void setChannelCount(int channels); | |
38 | |
39 /** | |
40 * Load a sample clip from a wav file. This can only happen once: | |
41 * construct a new ClipMixer if you want a different clip. The | |
42 * clip was recorded at a pitch with fundamental frequency clipF0, | |
43 * and should be scaled by level (in the range 0-1) when playing | |
44 * back. | |
45 */ | |
46 bool loadClipData(QString clipFilePath, double clipF0, double level); | |
47 | |
48 void reset(); // discarding any playing notes | |
49 | |
50 struct NoteStart { | |
51 sv_frame_t frameOffset; // within current processing block | |
52 float frequency; // Hz | |
53 float level; // volume in range (0,1] | |
54 float pan; // range [-1,1] | |
55 }; | |
56 | |
57 struct NoteEnd { | |
58 sv_frame_t frameOffset; // in current processing block | |
59 float frequency; // matching note start | |
60 }; | |
61 | |
62 void mix(float **toBuffers, | |
63 float gain, | |
64 std::vector<NoteStart> newNotes, | |
65 std::vector<NoteEnd> endingNotes); | |
66 | |
67 private: | |
68 int m_channels; | |
69 sv_samplerate_t m_sampleRate; | |
70 sv_frame_t m_blockSize; | |
71 | |
72 QString m_clipPath; | |
73 | |
74 float *m_clipData; | |
75 sv_frame_t m_clipLength; | |
76 double m_clipF0; | |
77 sv_samplerate_t m_clipRate; | |
78 | |
79 std::vector<NoteStart> m_playing; | |
80 | |
81 double getResampleRatioFor(double frequency); | |
82 sv_frame_t getResampledClipDuration(double frequency); | |
83 | |
84 void mixNote(float **toBuffers, | |
85 float *levels, | |
86 float frequency, | |
87 sv_frame_t sourceOffset, // within resampled note | |
88 sv_frame_t targetOffset, // within target buffer | |
89 sv_frame_t sampleCount, | |
90 bool isEnd); | |
91 }; | |
92 | |
93 | |
94 #endif |