コード例 #1
0
ファイル: FMgrains3.c プロジェクト: DarienBrito/FMgrains-
//CARRIER
// compare symbol with stored symbols to determine which wavetable should be made
void FMSet(fmsynth *x, t_symbol *s) {
	if (s == sineMess)
		FillSine(x);
	else if (s == squareMess)
		FillSquare(x);
    else if (s == triMess)
        FillTri(x);
    else if (s == sawMess)
        FillSaw(x);
    else if (s == phasorMess)
        FillPhasor(x);
    //MODULATOR
    else if (s == sineMessMod)
		FillSineMod(x);
	else if (s == squareMessMod)
		FillSquareMod(x);
    else if (s == triMessMod)
        FillTriMod(x);
    else if (s == sawMessMod)
        FillSawMod(x);
    else if (s == phasorMessMod)
        FillPhasorMod(x);
}
コード例 #2
0
ファイル: FMgrains3.c プロジェクト: DarienBrito/FMgrains-
void *FMNew (double minfreq, double maxfreq, double minModFreq, double maxModFreq, double dex, double minwin, double maxwin){
    fmsynth *x;
    //VARIABLE FOR CREATING THE OBJECT
    x = (fmsynth *) object_alloc(myClass);

    dsp_setup((t_pxobject *)x,0);               //No signal inlets

    floatin((t_object *) x, 6);                 // Inlet for max grain val
    floatin((t_object *) x, 5);                 // Inlet for min grain val
    floatin((t_object *) x, 4);                 // Inlet for Modulator Depth
    floatin((t_object *) x, 3);                 // Inlet for min Modulator Freq
    floatin((t_object *) x, 2);                 // Inlet for max Modulator Freq
    floatin((t_object *) x, 1);                 // Inlet for Max Carrier Freq
    
    outlet_new((t_pxobject *)x, "signal");      // Add a signal outlet
    
    //INITIAL VALUES (A_GIMME seems to require this initialization
    x->minFreq = minfreq = 220.0;
    x->maxFreq = maxfreq = 300.0;
    x->minModFreq = minModFreq = 0.;
    x->maxModFreq = maxModFreq = 0.;
    x->modIndex = dex= 1.;
    x->min = minwin = 0.01;
    x->max = maxwin = 0.1;
    x->winFlag = 0;
    
    // Allocate memory for wavetables:
    x->waveTable = (double *)sysmem_newptr(sizeof(double) * kTableLength);
    x->waveTable2 = (double *)sysmem_newptr(sizeof(double) * kTableLength);
    x->window = (double *)sysmem_newptr(sizeof(double) * kTableLength);

    FillSine(x);                                //Default waveform for Carrier is Sine
    FillSineMod(x);                             //Default waveform for Modulator is Sine
    FillWindow(x);                              //Default window is Hamming

    return (x);
}
コード例 #3
0
void SignalGenerator::startRunning()
{
	IDeckLinkDisplayMode*	videoDisplayMode = NULL;
	BMDVideoOutputFlags		videoOutputFlags = 0;
	QVariant v;
	// Determine the audio and video properties for the output stream
	v = ui->outputSignalPopup->itemData(ui->outputSignalPopup->currentIndex());
	outputSignal = (OutputSignal)v.value<int>();	
	
	v = ui->audioChannelPopup->itemData(ui->audioChannelPopup->currentIndex());
	audioChannelCount = v.value<int>();	
	
	v = ui->audioSampleDepthPopup->itemData(ui->audioSampleDepthPopup->currentIndex());
	audioSampleDepth = v.value<int>();	
	audioSampleRate = bmdAudioSampleRate48kHz;
	
	//
	// - Extract the IDeckLinkDisplayMode from the display mode popup menu (stashed in the item's tag)
	v = ui->videoFormatPopup->itemData(ui->videoFormatPopup->currentIndex());
	videoDisplayMode = (IDeckLinkDisplayMode *)v.value<void*>();
	
	frameWidth = videoDisplayMode->GetWidth();
	frameHeight = videoDisplayMode->GetHeight();
	
	videoDisplayMode->GetFrameRate(&frameDuration, &frameTimescale);
	// Calculate the number of frames per second, rounded up to the nearest integer.  For example, for NTSC (29.97 FPS), framesPerSecond == 30.
	framesPerSecond = (frameTimescale + (frameDuration-1))  /  frameDuration;
	
	if (videoDisplayMode->GetDisplayMode() == bmdModeNTSC ||
		videoDisplayMode->GetDisplayMode() == bmdModeNTSC2398 ||
		videoDisplayMode->GetDisplayMode() == bmdModePAL)
	{
		timeCodeFormat = bmdTimecodeVITC;
		videoOutputFlags |= bmdVideoOutputVITC;
	}
	else
	{
		timeCodeFormat = bmdTimecodeRP188Any;
		videoOutputFlags |= bmdVideoOutputRP188;
	}

	if (timeCode)
		delete timeCode;
	timeCode = new Timecode(framesPerSecond);


	// Set the video output mode
	if (deckLinkOutput->EnableVideoOutput(videoDisplayMode->GetDisplayMode(), videoOutputFlags) != S_OK)
		goto bail;
	
	// Set the audio output mode
	if (deckLinkOutput->EnableAudioOutput(bmdAudioSampleRate48kHz, audioSampleDepth, audioChannelCount, bmdAudioOutputStreamTimestamped) != S_OK)
		goto bail;
	
	
	// Generate one second of audio tone
	audioSamplesPerFrame = ((audioSampleRate * frameDuration) / frameTimescale);
	audioBufferSampleLength = (framesPerSecond * audioSampleRate * frameDuration) / frameTimescale;
	audioBuffer = malloc(audioBufferSampleLength * audioChannelCount * (audioSampleDepth / 8));
	if (audioBuffer == NULL)
		goto bail;
	FillSine(audioBuffer, audioBufferSampleLength, audioChannelCount, audioSampleDepth);
	
	// Generate a frame of black
	if (deckLinkOutput->CreateVideoFrame(frameWidth, frameHeight, frameWidth*2, bmdFormat8BitYUV, bmdFrameFlagDefault, &videoFrameBlack) != S_OK)
		goto bail;
	FillBlack(videoFrameBlack);
	
	// Generate a frame of colour bars
	if (deckLinkOutput->CreateVideoFrame(frameWidth, frameHeight, frameWidth*2, bmdFormat8BitYUV, bmdFrameFlagDefault, &videoFrameBars) != S_OK)
		goto bail;
	FillColourBars(videoFrameBars);
	
	// Begin video preroll by scheduling a second of frames in hardware
	totalFramesScheduled = 0;
	for (unsigned int i = 0; i < framesPerSecond; i++)
		scheduleNextFrame(true);
	
	// Begin audio preroll.  This will begin calling our audio callback, which will start the DeckLink output stream.
	totalAudioSecondsScheduled = 0;
	if (deckLinkOutput->BeginAudioPreroll() != S_OK)
		goto bail;
	
	// Success; update the UI
	running = true;
	ui->startButton->setText("Stop");
	// Disable the user interface while running (prevent the user from making changes to the output signal)
	enableInterface(false);
	
	return;
	
bail:
	QMessageBox::critical(this, "Failed to start output", "Failed to start output");
	// *** Error-handling code.  Cleanup any resources that were allocated. *** //
	stopRunning();
}
コード例 #4
0
void	CSignalGeneratorDlg::StartRunning ()
{
	IDeckLinkDisplayMode*	videoDisplayMode = NULL;
	BMDVideoOutputFlags		videoOutputFlags = bmdVideoOutputFlagDefault;
	int						curSelection;
	CString					videoFormatName;

	curSelection = m_videoFormatCombo.GetCurSel();
	m_videoFormatCombo.GetLBText(curSelection, videoFormatName);
	if (videoFormatName.Find(_T(" 3D"), 0) != -1)
		videoOutputFlags = bmdVideoOutputDualStream3D;
	
	// Determine the audio and video properties for the output stream
	m_outputSignal = (OutputSignal)m_outputSignalCombo.GetCurSel();
	m_audioChannelCount = m_audioChannelCombo.GetItemData(m_audioChannelCombo.GetCurSel());
	m_audioSampleDepth = (BMDAudioSampleType)m_audioSampleDepthCombo.GetItemData(m_audioSampleDepthCombo.GetCurSel());
	m_audioSampleRate = bmdAudioSampleRate48kHz;
	//
	// - Extract the IDeckLinkDisplayMode from the display mode popup menu (stashed in the item's tag)
	videoDisplayMode = (IDeckLinkDisplayMode*)m_videoFormatCombo.GetItemDataPtr(m_videoFormatCombo.GetCurSel());
	m_frameWidth = videoDisplayMode->GetWidth();
	m_frameHeight = videoDisplayMode->GetHeight();
	videoDisplayMode->GetFrameRate(&m_frameDuration, &m_frameTimescale);
	// Calculate the number of frames per second, rounded up to the nearest integer.  For example, for NTSC (29.97 FPS), framesPerSecond == 30.
	m_framesPerSecond = (unsigned long)((m_frameTimescale + (m_frameDuration-1))  /  m_frameDuration);
	
	// Set the video output mode
	if (m_deckLinkOutput->EnableVideoOutput(videoDisplayMode->GetDisplayMode(), videoOutputFlags) != S_OK)
		goto bail;

	// Set the audio output mode
	if (m_deckLinkOutput->EnableAudioOutput(bmdAudioSampleRate48kHz, m_audioSampleDepth, m_audioChannelCount, bmdAudioOutputStreamTimestamped) != S_OK)
		goto bail;
	
	// Generate one second of audio tone
	m_audioSamplesPerFrame = (unsigned long)((m_audioSampleRate * m_frameDuration) / m_frameTimescale);
	m_audioBufferSampleLength = (unsigned long)((m_framesPerSecond * m_audioSampleRate * m_frameDuration) / m_frameTimescale);
	m_audioBuffer = HeapAlloc(GetProcessHeap(), 0, (m_audioBufferSampleLength * m_audioChannelCount * (m_audioSampleDepth / 8)));
	if (m_audioBuffer == NULL)
		goto bail;
	FillSine(m_audioBuffer, m_audioBufferSampleLength, m_audioChannelCount, m_audioSampleDepth);
	
	// Generate a frame of black
	m_videoFrameBlack = CreateBlackFrame();
	if (! m_videoFrameBlack)
		goto bail;

	// Generate a frame of colour bars
	m_videoFrameBars = CreateBarsFrame();
	if (! m_videoFrameBars)
		goto bail;

	// Begin video preroll by scheduling a second of frames in hardware
	m_totalFramesScheduled = 0;
	for (unsigned i = 0; i < m_framesPerSecond; i++)
		ScheduleNextFrame(true);
	
	// Begin audio preroll.  This will begin calling our audio callback, which will start the DeckLink output stream.
	m_totalAudioSecondsScheduled = 0;
	if (m_deckLinkOutput->BeginAudioPreroll() != S_OK)
		goto bail;
	
	// Success; update the UI
	m_running = true;
	m_startButton.SetWindowText(_T("Stop"));
	// Disable the user interface while running (prevent the user from making changes to the output signal)
	EnableInterface(FALSE);
	
	return;
	
bail:
	// *** Error-handling code.  Cleanup any resources that were allocated. *** //
	StopRunning();
}
コード例 #5
0
void TestPattern::StartRunning()
{
	HRESULT					result;
	unsigned long			audioSamplesPerFrame;
	IDeckLinkVideoFrame*	rightFrame;
	VideoFrame3D*			frame3D;

	m_frameWidth = m_displayMode->GetWidth();
	m_frameHeight = m_displayMode->GetHeight();
	m_displayMode->GetFrameRate(&m_frameDuration, &m_frameTimescale);

	// Calculate the number of frames per second, rounded up to the nearest integer.  For example, for NTSC (29.97 FPS), framesPerSecond == 30.
	m_framesPerSecond = (unsigned long)((m_frameTimescale + (m_frameDuration-1))  /  m_frameDuration);

	// Set the video output mode
	result = m_deckLinkOutput->EnableVideoOutput(m_displayMode->GetDisplayMode(), m_config->m_outputFlags);
	if (result != S_OK)
	{
		fprintf(stderr, "Failed to enable video output. Is another application using the card?\n");
		goto bail;
	}

	// Set the audio output mode
	result = m_deckLinkOutput->EnableAudioOutput(bmdAudioSampleRate48kHz, m_config->m_audioSampleDepth, m_config->m_audioChannels, bmdAudioOutputStreamContinuous);
	if (result != S_OK)
	{
		fprintf(stderr, "Failed to enable audio output\n");
		goto bail;
	}

	// Generate one second of audio
	m_audioBufferSampleLength = (unsigned long)((m_framesPerSecond * m_audioSampleRate * m_frameDuration) / m_frameTimescale);
	m_audioBuffer = valloc(m_audioBufferSampleLength * m_config->m_audioChannels * (m_config->m_audioSampleDepth / 8));

	if (m_audioBuffer == NULL)
	{
		fprintf(stderr, "Failed to allocate audio buffer memory\n");
		goto bail;
	}

	// Zero the buffer (interpreted as audio silence)
	memset(m_audioBuffer, 0x0, (m_audioBufferSampleLength * m_config->m_audioChannels * m_config->m_audioSampleDepth / 8));
	audioSamplesPerFrame = (unsigned long)((m_audioSampleRate * m_frameDuration) / m_frameTimescale);

	if (m_outputSignal == kOutputSignalPip)
		FillSine(m_audioBuffer, audioSamplesPerFrame, m_config->m_audioChannels, m_config->m_audioSampleDepth);
	else
		FillSine((void*)((unsigned long)m_audioBuffer + (audioSamplesPerFrame * m_config->m_audioChannels * m_config->m_audioSampleDepth / 8)), (m_audioBufferSampleLength - audioSamplesPerFrame), m_config->m_audioChannels, m_config->m_audioSampleDepth);

	// Generate a frame of black
	if (CreateFrame(&m_videoFrameBlack, FillBlack) != S_OK)
		goto bail;

	if (m_config->m_outputFlags & bmdVideoOutputDualStream3D)
	{
		frame3D = new VideoFrame3D(m_videoFrameBlack);
		m_videoFrameBlack->Release();
		m_videoFrameBlack = frame3D;
		frame3D = NULL;
	}

	// Generate a frame of colour bars
	if (CreateFrame(&m_videoFrameBars, FillForwardColourBars) != S_OK)
		goto bail;

	if (m_config->m_outputFlags & bmdVideoOutputDualStream3D)
	{
		if (CreateFrame(&rightFrame, FillReverseColourBars) != S_OK)
			goto bail;

		frame3D = new VideoFrame3D(m_videoFrameBars, rightFrame);
		m_videoFrameBars->Release();
		rightFrame->Release();
		m_videoFrameBars = frame3D;
		frame3D = NULL;
	}

	// Begin video preroll by scheduling a second of frames in hardware
	m_totalFramesScheduled = 0;
	m_totalFramesDropped = 0;
	m_totalFramesCompleted = 0;
	for (unsigned i = 0; i < m_framesPerSecond; i++)
		ScheduleNextFrame(true);

	// Begin audio preroll.  This will begin calling our audio callback, which will start the DeckLink output stream.
	m_audioBufferOffset = 0;
	if (m_deckLinkOutput->BeginAudioPreroll() != S_OK)
	{
		fprintf(stderr, "Failed to begin audio preroll\n");
		goto bail;
	}

	m_running = true;

	return;

bail:
	// *** Error-handling code.  Cleanup any resources that were allocated. *** //
	StopRunning();
}