当前位置: 首页>>代码示例>>C++>>正文


C++ AudioTransportSource类代码示例

本文整理汇总了C++中AudioTransportSource的典型用法代码示例。如果您正苦于以下问题:C++ AudioTransportSource类的具体用法?C++ AudioTransportSource怎么用?C++ AudioTransportSource使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了AudioTransportSource类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: thread

namespace playback {
AudioDeviceManager dm;
AudioFormatManager fm;
AudioSourcePlayer asp;
AudioTransportSource ts;
ScopedPointer<AudioFormatReaderSource> frs;
TimeSliceThread thread("audio playback");

class playbackListener : public ChangeListener {
	base::lisp &gl;
public:
	base::string functionId;
	bool enabled;
	playbackListener(base::lisp &gli) : gl(gli), enabled(false) {}
	void changeListenerCallback(ChangeBroadcaster *source) override {
		if (source == &ts && enabled) {
			gl.eval(base::strs("(", functionId, ")"));
		}
	}
};

playbackListener *pl = nullptr;

void init(base::lisp &gl) {
	fm.registerBasicFormats();
	thread.startThread(3);
	dm.addAudioCallback(&asp);
	asp.setSource(&ts);
	pl = new playbackListener(gl);
	ts.addChangeListener(pl);
}

void shutdown() {
	ts.removeAllChangeListeners();
	ts.setSource(nullptr);
	asp.setSource(nullptr);
	dm.removeAudioCallback(&asp);
	delete pl;
	pl = nullptr;
}

//- LISP API -
// playback-set-file (string)fileName -> t/nil
base::cell_t set_file(base::lisp &gl, base::cell_t c, base::cells_t &) {
	if (base::lisp::validate(c, base::cell::list(1), base::cell::typeString)) {
		const auto &fname = c + 1;

		// stop current playback
		ts.stop();
		ts.setSource(nullptr);
		frs = nullptr;
		AudioFormatReader *r;

		// ectract CUE information (if any)
		std::regex cue("^(.*):(\\d+):(\\d+)$");
		std::smatch result;
		std::regex_search(fname->s, result, cue);
		if (result.size() == 4) {
			// is cue
			int32 start = base::fromStr<int32>(result[2].str());
			int32 end = base::fromStr<int32>(result[3].str());
			int32 duration = end - start;

			AudioFormatReader *tr = fm.createReaderFor(File(result[1].str()));

			// start, end are in frames (1 frame = 1/75 second) - convert to sample
			float samplesInOneSecond = tr->sampleRate; // AudioSubsectionReader will handle channels count
			float startSecond = (float)start / 75.0f;
			float durationSecond = (float)duration / 75.0f;
			float startSample = startSecond * samplesInOneSecond;
			float durationSamples = durationSecond * samplesInOneSecond;

			// some CUE may have 0 length (play to end)
			if (end <= start)
				durationSamples = tr->lengthInSamples;

			r = new AudioSubsectionReader(tr, (int)startSample, (int)durationSamples, true);
		}
		else {
			// regular file
			r = fm.createReaderFor(File(fname->s));
		}

		if (r) {
			frs = new AudioFormatReaderSource(r, true);
			ts.setSource(frs, 32768, &thread, r->sampleRate);
			return gl.t();
		}
		gl.signalError(base::strs("file not found or file format not supported: ", fname->s));
		return gl.nil();
	}
	gl.signalError("playback-set-file: invalid arguments, expected (string)");
	return gl.nil();
}

// playback-unload-file
base::cell_t unload_file(base::lisp &gl, base::cell_t, base::cells_t &) {
	ts.stop();
	ts.setSource(nullptr);
	frs = nullptr;
//.........这里部分代码省略.........
开发者ID:c41x,项目名称:Kiwano,代码行数:101,代码来源:playback.hpp

示例2: shutdown

void shutdown() {
	ts.removeAllChangeListeners();
	ts.setSource(nullptr);
	asp.setSource(nullptr);
	dm.removeAudioCallback(&asp);
	delete pl;
	pl = nullptr;
}
开发者ID:c41x,项目名称:Kiwano,代码行数:8,代码来源:playback.hpp

示例3: set_file

//- LISP API -
// playback-set-file (string)fileName -> t/nil
base::cell_t set_file(base::lisp &gl, base::cell_t c, base::cells_t &) {
	if (base::lisp::validate(c, base::cell::list(1), base::cell::typeString)) {
		const auto &fname = c + 1;

		// stop current playback
		ts.stop();
		ts.setSource(nullptr);
		frs = nullptr;
		AudioFormatReader *r;

		// ectract CUE information (if any)
		std::regex cue("^(.*):(\\d+):(\\d+)$");
		std::smatch result;
		std::regex_search(fname->s, result, cue);
		if (result.size() == 4) {
			// is cue
			int32 start = base::fromStr<int32>(result[2].str());
			int32 end = base::fromStr<int32>(result[3].str());
			int32 duration = end - start;

			AudioFormatReader *tr = fm.createReaderFor(File(result[1].str()));

			// start, end are in frames (1 frame = 1/75 second) - convert to sample
			float samplesInOneSecond = tr->sampleRate; // AudioSubsectionReader will handle channels count
			float startSecond = (float)start / 75.0f;
			float durationSecond = (float)duration / 75.0f;
			float startSample = startSecond * samplesInOneSecond;
			float durationSamples = durationSecond * samplesInOneSecond;

			// some CUE may have 0 length (play to end)
			if (end <= start)
				durationSamples = tr->lengthInSamples;

			r = new AudioSubsectionReader(tr, (int)startSample, (int)durationSamples, true);
		}
		else {
			// regular file
			r = fm.createReaderFor(File(fname->s));
		}

		if (r) {
			frs = new AudioFormatReaderSource(r, true);
			ts.setSource(frs, 32768, &thread, r->sampleRate);
			return gl.t();
		}
		gl.signalError(base::strs("file not found or file format not supported: ", fname->s));
		return gl.nil();
	}
	gl.signalError("playback-set-file: invalid arguments, expected (string)");
	return gl.nil();
}
开发者ID:c41x,项目名称:Kiwano,代码行数:53,代码来源:playback.hpp

示例4: gain

// (playback-gain (float|optional)gain) -> t/nil | gain
base::cell_t gain(base::lisp &gl, base::cell_t c, base::cells_t &ret) {
	if (pl) {
		if (base::lisp::validate(c, base::cell::listRange(1), base::cell::typeFloat)) {
			// setter
			ts.setGain((c + 1)->f);
			return gl.t();
		}
		else if (base::lisp::validate(c, base::cell::list(0))) {
			// getter
			ret.push_back(base::cell(ts.getGain()));
			return ret.end();
		}
		gl.signalError("playback-gain: invalid arguments, expected ((optional) float)");
	}
	return gl.nil();
}
开发者ID:c41x,项目名称:Kiwano,代码行数:17,代码来源:playback.hpp

示例5: init

void init(base::lisp &gl) {
	fm.registerBasicFormats();
	thread.startThread(3);
	dm.addAudioCallback(&asp);
	asp.setSource(&ts);
	pl = new playbackListener(gl);
	ts.addChangeListener(pl);
}
开发者ID:c41x,项目名称:Kiwano,代码行数:8,代码来源:playback.hpp

示例6: seek

// playback-seek (float)posSeconds
base::cell_t seek(base::lisp &gl, base::cell_t c, base::cells_t &) {
	if (base::lisp::validate(c, base::cell::list(1), base::cell::typeFloat)) {
		const auto &pos = c + 1;
		ts.setPosition((double)pos->f);
		return gl.nil();
	}
	gl.signalError("playback-seek: invalid arguments, expected (float)");
	return gl.nil();
}
开发者ID:c41x,项目名称:Kiwano,代码行数:10,代码来源:playback.hpp

示例7: buttonClicked

 void buttonClicked (Button* buttonThatWasClicked) override
 {
     if (buttonThatWasClicked == &startStopButton)
     {
         if (transportSource.isPlaying())
         {
             transportSource.stop();
         }
         else
         {
             transportSource.setPosition (0);
             transportSource.start();
         }
     }
     else if (buttonThatWasClicked == &followTransportButton)
     {
         thumbnail->setFollowsTransport (followTransportButton.getToggleState());
     }
 }
开发者ID:AydinSakar,项目名称:JUCE,代码行数:19,代码来源:AudioPlaybackDemo.cpp

示例8: loadFileIntoTransport

    void loadFileIntoTransport (const File& audioFile)
    {
        // unload the previous file source and delete it..
        transportSource.stop();
        transportSource.setSource (nullptr);
        currentAudioFileSource = nullptr;

        AudioFormatReader* reader = formatManager.createReaderFor (audioFile);

        if (reader != nullptr)
        {
            currentAudioFileSource = new AudioFormatReaderSource (reader, true);

            // ..and plug it into our transport source
            transportSource.setSource (currentAudioFileSource,
                                       32768,                   // tells it to buffer this many samples ahead
                                       &thread,                 // this is the background thread to use for reading-ahead
                                       reader->sampleRate);     // allows for sample rate correction
        }
    }
开发者ID:AydinSakar,项目名称:JUCE,代码行数:20,代码来源:AudioPlaybackDemo.cpp

示例9: set_file

//- LISP API -
// playback-set-file (string)fileName -> t/nil
base::cell_t set_file(base::lisp &gl, base::cell_t c, base::cells_t &) {
    if (base::lisp::validate(c, base::cell::list(1), base::cell::typeString)) {
        const auto &fname = c + 1;

        // stop current playback
        ts.stop();
        ts.setSource(nullptr);
        frs = nullptr;

        AudioFormatReader *r;

        // ectract CUE information (if any)
        std::regex cue("^(.*):(\\d+):(\\d+)$");
        std::smatch result;
        std::regex_search(fname->s, result, cue);
        if (result.size() == 4) {
            // is cue
            int32 start = base::fromStr<int32>(result[2].str());
            int32 end = base::fromStr<int32>(result[3].str());
            AudioFormatReader *tr = fm.createReaderFor(File(result[1].str()));
            r = new AudioSubsectionReader(tr, start, end - start, true);
        }
        else {
            // regular file
            r = fm.createReaderFor(File(fname->s));
        }

        if (r) {
            frs = new AudioFormatReaderSource(r, true);
            ts.setSource(frs, 32768, &thread, r->sampleRate);
            return gl.t();
        }
        gl.signalError(base::strs("file not found or file format not supported: ", fname->s));
        return gl.nil();
    }
    gl.signalError("playback-set-file: invalid arguments, expected (string)");
    return gl.nil();
}
开发者ID:Robert-yeh,项目名称:Kiwano,代码行数:40,代码来源:playback.hpp

示例10: finished_playing

// playback-finished -> t/nil
base::cell_t finished_playing(base::lisp &gl, base::cell_t, base::cells_t &) {
	if (ts.hasStreamFinished())
		return gl.t();
	return gl.nil();
}
开发者ID:c41x,项目名称:Kiwano,代码行数:6,代码来源:playback.hpp

示例11: is_playing

// playback-is-playing -> t/nil
base::cell_t is_playing(base::lisp &gl, base::cell_t, base::cells_t &) {
	if (ts.isPlaying())
		return gl.t();
	return gl.nil();
}
开发者ID:c41x,项目名称:Kiwano,代码行数:6,代码来源:playback.hpp

示例12: get_pos

// playback-get-pos -> (float)/playback position in seconds/
base::cell_t get_pos(base::lisp &gl, base::cell_t, base::cells_t &ret) {
	ret.push_back(base::cell(float(ts.getCurrentPosition())));
	return ret.end();
}
开发者ID:c41x,项目名称:Kiwano,代码行数:5,代码来源:playback.hpp

示例13: length

// playback-length -> (float)/total time in seconds/
base::cell_t length(base::lisp &gl, base::cell_t, base::cells_t &ret) {
	ret.push_back(base::cell(float(ts.getLengthInSeconds())));
	return ret.end();
}
开发者ID:c41x,项目名称:Kiwano,代码行数:5,代码来源:playback.hpp

示例14: stop

// playback-stop
base::cell_t stop(base::lisp &gl, base::cell_t, base::cells_t &) {
	ts.stop();
	return gl.nil();
}
开发者ID:c41x,项目名称:Kiwano,代码行数:5,代码来源:playback.hpp

示例15: unload_file

// playback-unload-file
base::cell_t unload_file(base::lisp &gl, base::cell_t, base::cells_t &) {
	ts.stop();
	ts.setSource(nullptr);
	frs = nullptr;
	return gl.nil();
}
开发者ID:c41x,项目名称:Kiwano,代码行数:7,代码来源:playback.hpp


注:本文中的AudioTransportSource类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。