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


C++ PlayerObject::openInStream方法代码示例

本文整理汇总了C++中PlayerObject::openInStream方法的典型用法代码示例。如果您正苦于以下问题:C++ PlayerObject::openInStream方法的具体用法?C++ PlayerObject::openInStream怎么用?C++ PlayerObject::openInStream使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PlayerObject的用法示例。


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

示例1: pyCreatePlayer

PyObject*
pyGetMetadata(PyObject* self, PyObject* args) {
	PyObject* songObj = NULL;
	if(!PyArg_ParseTuple(args, "O:getMetadata", &songObj))
		return NULL;
	
	PyObject* returnObj = NULL;
	PlayerObject* player = (PlayerObject*) pyCreatePlayer(NULL);
	if(!player) goto final;
	player->nextSongOnEof = 0;
	player->skipPyExceptions = 0;
	Py_INCREF(songObj);
	player->curSong = songObj;
	player->openInStream();
	if(PyErr_Occurred()) goto final;
	
	returnObj = player->curSongMetadata();
	
final:
开发者ID:bryanjos,项目名称:music-player,代码行数:19,代码来源:ffmpeg_getmetadata.cpp

示例2: pyCreatePlayer

PyObject *
pyCalcReplayGain(PyObject* self, PyObject* args, PyObject* kws) {
	PyObject* songObj = NULL;
	static const char *kwlist[] = {
		"song",
		NULL};
	if(!PyArg_ParseTupleAndKeywords(
			args, kws, "O:calcReplayGain", (char**)kwlist,
			&songObj
			))
		return NULL;
	
	PyObject* returnObj = NULL;
	PlayerObject* player = NULL;
	ReplayGainBuffer* buffer = NULL;
	unsigned long totalFrameCount = 0;
	size_t samplePos = 0;
	size_t windowCount = 0;
	
	player = (PlayerObject*) pyCreatePlayer(NULL);
	if(!player) goto final;
	player->lock.enabled = false;
	player->setAudioTgt(SAMPLERATE, NUMCHANNELS);
	player->nextSongOnEof = 0;
	player->skipPyExceptions = 0;
	player->playing = true; // otherwise audio_decode_frame() wont read
	player->volume = 1; player->volumeSmoothClip.setX(1, 1); // avoid volume adjustments
	assert(!player->volumeAdjustNeeded());
	Py_INCREF(songObj);
	player->curSong = songObj;
	if(PyObject_HasAttrString(songObj, "gain"))
		printf("pyCalcReplayGain: warning: song has gain already - this will lead to wrong gain calculation\n");
	if(!player->openInStream()) goto final;
	if(PyErr_Occurred()) goto final;
	if(!player->isInStreamOpened()) goto final;
	
	buffer = (ReplayGainBuffer*)malloc(sizeof(ReplayGainBuffer));
	memset(buffer, 0, sizeof(ReplayGainBuffer));
	
	while (player->processInStream()) {
		if(PyErr_Occurred()) goto final;
		for(auto& it : player->inStreamBuffer()->chunks) {		
			totalFrameCount += it.size() / NUMCHANNELS / 2 /* S16 */;
			
			short channel = 0;
			for(size_t i = 0; i < it.size() / 2; ++i) {
				int16_t* sampleAddr = (int16_t*) it.pt() + i;
				int16_t sample = *sampleAddr; // TODO: endian swap?
				// It is by purpose that we don't normalize to [-1,1] but stay in the range [-0x8000,0x7fff].
				// That is because it was originially based on CD data, which is 16-bit signed integers.
				float sampleFloat = sample;
				
				buffer->channels[channel].stages[0].data[samplePos + MAX_FILTER_ORDER] = sampleFloat;
				
				++channel;
				if(channel >= NUMCHANNELS) {
					channel = 0;
					++samplePos;
					if(samplePos >= MAX_SAMPLES_PER_WINDOW) {
						// buffer is full. i.e. we have a full window. handle it.
						replayGainHandleWindow(buffer);
						++windowCount;
						
						// move on now.
						for(int chan = 0; chan < NUMCHANNELS; ++chan)
							for(int stage = 0; stage < NUM_REPLAYGAIN_STAGES; ++stage)
								memcpy(
									   buffer->channels[chan].stages[stage].data,
									   buffer->channels[chan].stages[stage].data + MAX_SAMPLES_PER_WINDOW,
									   MAX_FILTER_ORDER * sizeof(buffer->channels[0].stages[0].data[0]));
						samplePos = 0;
					}
				}
			}
		}
		player->inStreamBuffer()->clear();
	}
	{
		double songDuration = (double)totalFrameCount / SAMPLERATE;
		
		float gain = 0;
		int64_t upperLoudness = (int64_t) ceil(windowCount * (1.0 - REPLAYGAIN_LOUD_PERC));
		for(int i = sizeof(buffer->loudnessTable)/sizeof(buffer->loudnessTable[0]) - 1; i >= 0; --i) {
			upperLoudness -= buffer->loudnessTable[i];
			if(upperLoudness <= 0) {
				gain = RG_PINK_REF - (float)i / RG_STEPS_per_dB;
				break;
			}
		}
		
		returnObj = PyTuple_New(2);
		PyTuple_SetItem(returnObj, 0, PyFloat_FromDouble(songDuration));
		PyTuple_SetItem(returnObj, 1, PyFloat_FromDouble(gain));
	}

final:
	if(buffer) free(buffer);
开发者ID:xssworm,项目名称:music-player,代码行数:97,代码来源:ffmpeg_replaygain.cpp


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