comparison audioio/ClipMixer.h @ 350:aebee52e86b3

Merge from branch tony_integration
author Chris Cannam
date Wed, 14 May 2014 09:54:46 +0100
parents 8d7f39df44ed
children 72c662fe7ea3
comparison
equal deleted inserted replaced
330:46b24009ce7a 350:aebee52e86b3
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 /**
23 * Mix in synthetic notes produced by resampling a prerecorded
24 * 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
26 * frequency, so long as they all use the same sample clip.
27 */
28
29 class ClipMixer
30 {
31 public:
32 ClipMixer(int channels, int sampleRate, int blockSize);
33 ~ClipMixer();
34
35 void setChannelCount(int channels);
36
37 /**
38 * Load a sample clip from a wav file. This can only happen once:
39 * construct a new ClipMixer if you want a different clip. The
40 * clip was recorded at a pitch with fundamental frequency clipF0,
41 * and should be scaled by level (in the range 0-1) when playing
42 * back.
43 */
44 bool loadClipData(QString clipFilePath, float clipF0, float level);
45
46 void reset(); // discarding any playing notes
47
48 struct NoteStart {
49 int frameOffset; // within current processing block
50 float frequency; // Hz
51 float level; // volume in range (0,1]
52 float pan; // range [-1,1]
53 };
54
55 struct NoteEnd {
56 int frameOffset; // in current processing block
57 float frequency; // matching note start
58 };
59
60 void mix(float **toBuffers,
61 float gain,
62 std::vector<NoteStart> newNotes,
63 std::vector<NoteEnd> endingNotes);
64
65 private:
66 int m_channels;
67 int m_sampleRate;
68 int m_blockSize;
69
70 QString m_clipPath;
71
72 float *m_clipData;
73 int m_clipLength;
74 float m_clipF0;
75 float m_clipRate;
76
77 std::vector<NoteStart> m_playing;
78
79 float getResampleRatioFor(float frequency);
80 int getResampledClipDuration(float frequency);
81
82 void mixNote(float **toBuffers,
83 float *levels,
84 float frequency,
85 int sourceOffset, // within resampled note
86 int targetOffset, // within target buffer
87 int sampleCount,
88 bool isEnd);
89 };
90
91
92 #endif