svapp
1.9
|
00001 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ 00002 00003 /* 00004 Sonic Visualiser 00005 An audio file viewer and annotation editor. 00006 Centre for Digital Music, Queen Mary, University of London. 00007 This file copyright 2006 Chris Cannam, 2006-2014 QMUL. 00008 00009 This program is free software; you can redistribute it and/or 00010 modify it under the terms of the GNU General Public License as 00011 published by the Free Software Foundation; either version 2 of the 00012 License, or (at your option) any later version. See the file 00013 COPYING included with this distribution for more information. 00014 */ 00015 00016 #ifndef CLIP_MIXER_H 00017 #define CLIP_MIXER_H 00018 00019 #include <QString> 00020 #include <vector> 00021 00029 class ClipMixer 00030 { 00031 public: 00032 ClipMixer(int channels, int sampleRate, int blockSize); 00033 ~ClipMixer(); 00034 00035 void setChannelCount(int channels); 00036 00044 bool loadClipData(QString clipFilePath, float clipF0, float level); 00045 00046 void reset(); // discarding any playing notes 00047 00048 struct NoteStart { 00049 int frameOffset; // within current processing block 00050 float frequency; // Hz 00051 float level; // volume in range (0,1] 00052 float pan; // range [-1,1] 00053 }; 00054 00055 struct NoteEnd { 00056 int frameOffset; // in current processing block 00057 float frequency; // matching note start 00058 }; 00059 00060 void mix(float **toBuffers, 00061 float gain, 00062 std::vector<NoteStart> newNotes, 00063 std::vector<NoteEnd> endingNotes); 00064 00065 private: 00066 int m_channels; 00067 int m_sampleRate; 00068 int m_blockSize; 00069 00070 QString m_clipPath; 00071 00072 float *m_clipData; 00073 int m_clipLength; 00074 float m_clipF0; 00075 float m_clipRate; 00076 00077 std::vector<NoteStart> m_playing; 00078 00079 float getResampleRatioFor(float frequency); 00080 int getResampledClipDuration(float frequency); 00081 00082 void mixNote(float **toBuffers, 00083 float *levels, 00084 float frequency, 00085 int sourceOffset, // within resampled note 00086 int targetOffset, // within target buffer 00087 int sampleCount, 00088 bool isEnd); 00089 }; 00090 00091 00092 #endif