view audioio/ClipMixer.h @ 308:289d65722123 tonioni

More work on mixing and file i/o for sample stuff
author Chris Cannam
date Tue, 07 Jan 2014 15:50:04 +0000
parents 9716c75499ef
children 8c59cc68eabd
line wrap: on
line source
/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */

/*
    Sonic Visualiser
    An audio file viewer and annotation editor.
    Centre for Digital Music, Queen Mary, University of London.
    This file copyright 2006 Chris Cannam, 2006-2014 QMUL.
    
    This program is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public License as
    published by the Free Software Foundation; either version 2 of the
    License, or (at your option) any later version.  See the file
    COPYING included with this distribution for more information.
*/

#ifndef _CLIP_MIXER_H_
#define _CLIP_MIXER_H_

#include <QString>
#include <vector>

/**
 * Mix in synthetic notes produced by resampling a prerecorded
 * clip. That is, this is a sampler.
 */

class ClipMixer
{
public:
    ClipMixer(int channels, int sampleRate, int blockSize);
    ~ClipMixer();

    void setChannelCount(int channels);
    
    bool loadClipData(QString clipFilePath, float clipF0);

    void reset(); // discarding any playing notes

    //!!! what can we find in common with the NoteData type and
    //!!! AudioGenerator's NoteOff?

    struct NoteStart {
	int frameOffset; // in current processing block
	float frequency; // Hz
	float level; // volume in range (0,1]
	float pan; // range [-1,1]
    };

    struct NoteEnd {
        float frequency; // matching note start
	int frameOffset; // in current processing block
    };

    void mix(float **toBuffers, 
             float gain,
	     std::vector<NoteStart> newNotes, 
	     std::vector<NoteEnd> endingNotes);

private:
    int m_channels;
    int m_sampleRate;
    int m_blockSize;

    QString m_clipPath;

    float *m_clipData;
    int m_clipLength;
    float m_clipF0;
    float m_clipRate;
};


#endif