int RageSoundReader_MP3::Read( float *buf, int iFrames )
{
	int iFramesWritten = 0;

	while( iFrames > 0 )
	{
		if( mad->outleft > 0 )
		{
			int iFramesToCopy = min( iFrames, int(mad->outleft / GetNumChannels()) );
			const int iSamplesToCopy = iFramesToCopy * GetNumChannels();
			const int iBytesToCopy = iSamplesToCopy * sizeof(float);

			memcpy( buf, mad->outbuf + mad->outpos, iBytesToCopy );

			buf += iSamplesToCopy;
			iFrames -= iFramesToCopy;
			iFramesWritten += iFramesToCopy;
			mad->outpos += iSamplesToCopy;
			mad->outleft -= iSamplesToCopy;
			continue;
		}

		/* Decode more from the MP3 stream. */
		int ret = do_mad_frame_decode();
		if( ret == 0 )
			return END_OF_FILE;
		if( ret == -1 )
			return ERROR;

		synth_output();
	}

	return iFramesWritten;
}
示例#2
0
bool CPattern::operator== (const CPattern &other) const
//-----------------------------------------------------
{
	if(GetNumRows() != other.GetNumRows()
		|| GetNumChannels() != other.GetNumChannels()
		|| GetOverrideSignature() != other.GetOverrideSignature()
		|| GetRowsPerBeat() != other.GetRowsPerBeat()
		|| GetRowsPerMeasure() != other.GetRowsPerMeasure())
		return false;
	if(m_ModCommands == nullptr || other.m_ModCommands == nullptr)
		return m_ModCommands == other.m_ModCommands;

	auto i = GetNumRows() * GetNumChannels();
	auto m1 = m_ModCommands, m2 = other.m_ModCommands;
	while(i--)
	{
		if(*m1 != *m2)
		{
			return false;
		}
		m1++;
		m2++;
	}
	return true;
}
示例#3
0
// Add or remove rows from the pattern.
bool CPattern::Resize(const ROWINDEX newRowCount, bool enforceFormatLimits)
//-------------------------------------------------------------------------
{
	CSoundFile &sndFile = GetSoundFile();
	ModCommand *newPattern;

	if(enforceFormatLimits)
	{
		const CModSpecifications& specs = sndFile.GetModSpecifications();
		if(newRowCount > specs.patternRowsMax || newRowCount < specs.patternRowsMin) return false;
	} else
	{
		if(newRowCount > MAX_PATTERN_ROWS || newRowCount < 1) return false;
	}

	if(m_ModCommands == nullptr
		|| newRowCount == m_Rows
		|| (newPattern = AllocatePattern(newRowCount, GetNumChannels())) == nullptr)
	{
		return false;
	}

	// Copy over pattern data
	memcpy(newPattern, m_ModCommands, GetNumChannels() * std::min(m_Rows, newRowCount) * sizeof(ModCommand));

	FreePattern(m_ModCommands);
	m_ModCommands = newPattern;
	m_Rows = newRowCount;

	return true;
}
示例#4
0
bool
libname::COggStreamSample::Load( const char *szFilename )
{

  vorbis_info * pInfo;
  if ( !m_pFile )
    m_pFile = fopen( szFilename, "rb");
  
  if( ov_open_callbacks( m_pFile , &m_OggFile, NULL, 0, OV_CALLBACKS_DEFAULT) < 0) 
  {
    cerr << "Input does not appear to be an Ogg bitstream." << endl;
    return false;
  }
  
  pInfo = ov_info(&m_OggFile,-1);

  SetNumChannels( pInfo->channels);  // number of channels
  SetFreq( pInfo->rate);             // The frequency of the sampling rate
  
  // Check the number of channels... always use 16-bit samples
  if (GetNumChannels() == 1)
    SetFormat( AL_FORMAT_MONO16 );
  else
    SetFormat( AL_FORMAT_STEREO16 );
  cerr << "Freq: "     << GetFreq() << endl;
  cerr << "Channels: " << GetNumChannels() << endl;
  cerr << "Encoded: "  << ov_comment(&m_OggFile,-1)->vendor << endl;
  
  m_lFileSize = ov_raw_total( &m_OggFile, -1);

  return true;
}
示例#5
0
BOOL CModDoc::ExpandPattern(PATTERNINDEX nPattern)
//------------------------------------------------
{
	ROWINDEX numRows;

	if(!m_SndFile.Patterns.IsValidPat(nPattern)
		|| (numRows = m_SndFile.Patterns[nPattern].GetNumRows()) > m_SndFile.GetModSpecifications().patternRowsMax / 2)
	{
		return false;
	}

	BeginWaitCursor();
	CriticalSection cs;
	GetPatternUndo().PrepareUndo(nPattern, 0, 0, GetNumChannels(), numRows, "Expand Pattern");
	bool success = m_SndFile.Patterns[nPattern].Expand();
	cs.Leave();
	EndWaitCursor();

	if(success)
	{
		SetModified();
		UpdateAllViews(NULL, PatternHint(nPattern).Data(), NULL);
	} else
	{
		GetPatternUndo().RemoveLastUndoStep();
	}
	return success;
}
示例#6
0
bool CPattern::Expand()
//---------------------
{
	const ROWINDEX newRows = m_Rows * 2;
	const CHANNELINDEX nChns = GetNumChannels();
	ModCommand *newPattern;

	if(!m_ModCommands
		|| newRows > GetSoundFile().GetModSpecifications().patternRowsMax
		|| (newPattern = AllocatePattern(newRows, nChns)) == nullptr)
	{
		return false;
	}

	for(ROWINDEX y = 0; y < m_Rows; y++)
	{
		memcpy(newPattern + y * 2 * nChns, m_ModCommands + y * nChns, nChns * sizeof(ModCommand));
	}

	FreePattern(m_ModCommands);
	m_ModCommands = newPattern;
	m_Rows = newRows;

	return true;
}
void ImageData::SetSpectralMode(const ImageSpectralMode& spectral_mode) {
  spectral_mode_ = spectral_mode;

  // Display some warnings if things don't line up.
  const int num_channels = GetNumChannels();
  const bool can_be_color =
      (num_channels == 3) || (num_channels == 1 && luminance_channel_only_);
  if (IsColorImage(spectral_mode) && !can_be_color) {
    std::string luminance_on_or_off;
    if (luminance_channel_only_) {
      luminance_on_or_off = "on";
    } else {
      luminance_on_or_off = "off";
    }
    LOG(WARNING)
        << "Spectral mode set to color but the image does not appear to be a "
        << "color image (" << num_channels << " channel(s), luminance-only = "
        << luminance_on_or_off << ").";
  }
  if (spectral_mode == SPECTRAL_MODE_HYPERSPECTRAL && num_channels <= 3) {
    LOG(WARNING)
        << "Spectral mode set to hyperspectral but number of spectra is too "
        << "low (" << num_channels << " spectral bands).";
  }
}
double* ImageData::GetMutableChannelData(const int channel_index) const {
  CHECK_GE(channel_index, 0) << "Channel index must be at least 0.";
  CHECK_LT(channel_index, GetNumChannels()) << "Channel index out of bounds.";

  // TODO: verify that this is the correct approach of getting the data array.
  // static_cast doesn't work here because the data is apparently uchar*.
  return (double*)(channels_[channel_index].data);  // NOLINT
}
示例#9
0
// To remove all channels whose index corresponds to false in the keepMask vector.
// Return true on success.
bool CModDoc::RemoveChannels(const std::vector<bool> &keepMask, bool verbose)
//---------------------------------------------------------------------------
{
	CHANNELINDEX nRemainingChannels = 0;
	//First calculating how many channels are to be left
	for(CHANNELINDEX nChn = 0; nChn < GetNumChannels(); nChn++)
	{
		if(keepMask[nChn]) nRemainingChannels++;
	}
	if(nRemainingChannels == GetNumChannels() || nRemainingChannels < m_SndFile.GetModSpecifications().channelsMin)
	{
		if(verbose)
		{
			CString str;
			if(nRemainingChannels == GetNumChannels())
				str = _T("No channels chosen to be removed.");
			else
				str = _T("No removal done - channel number is already at minimum.");
			Reporting::Information(str, _T("Remove Channels"));
		}
		return false;
	}

	BeginWaitCursor();
	// Create new channel order, with only channels from m_bChnMask left.
	std::vector<CHANNELINDEX> channels(nRemainingChannels, 0);
	CHANNELINDEX i = 0;
	for(CHANNELINDEX nChn = 0; nChn < GetNumChannels(); nChn++)
	{
		if(keepMask[nChn])
		{
			channels[i++] = nChn;
		}
	}
	const bool success = (ReArrangeChannels(channels) == nRemainingChannels);
	if(success)
	{
		SetModified();
		UpdateAllViews(nullptr, UpdateHint().ModType());
	}
	EndWaitCursor();
	return success;

}
示例#10
0
double ImageData::GetPixelValue(
    const int channel_index, const int row, const int col) const {

  CHECK(0 <= channel_index && channel_index < GetNumChannels())
      << "Channel index is out of bounds.";
  CHECK(0 <= row && row < image_size_.height) << "Row index is out of bounds.";
  CHECK(0 <= col && col < image_size_.width) << "Col index is out of bounds.";

  return channels_[channel_index].at<double>(row, col);
}
示例#11
0
void OmniMapD3D::Clear_Channels()
{
  for (int i = 0; i < GetNumChannels(); i++)
  {
    OmniMapChannelD3D *channelD3D = (OmniMapChannelD3D *) GetChannel(i);
    if (channelD3D != NULL)
      delete channelD3D;
  }
  ClearChannelMap();
}
示例#12
0
void ImageData::InterpolateColorFrom(const ImageData& color_image) {
  CHECK_EQ(GetNumChannels(), 1)  // If other 2 channels are hidden, ignore them.
      << "Color can only be interpolated for single-channel images.";
  CHECK_EQ(color_image.channels_.size(), 3)  // Consider hidden channels.
      << "The given image must have color information for interpolation.";

  channels_.resize(3);
  InterpolateColor(color_image.channels_, &channels_);
  spectral_mode_ = color_image.spectral_mode_;
  luminance_channel_only_ = false;
}
示例#13
0
//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CChoreoActor::MarkForSaveAll( bool mark )
{
	SetMarkedForSave( mark );

	int c = GetNumChannels();
	for ( int i = 0; i < c; i++ )
	{
		CChoreoChannel *channel = GetChannel( i );
		channel->MarkForSaveAll( mark );
	}
}
示例#14
0
//-----------------------------------------------------------------------------
// Purpose: 
// Input  : *name - 
// Output : CChoreoChannel
//-----------------------------------------------------------------------------
CChoreoChannel *CChoreoActor::FindChannel( const char *name )
{
	int c = GetNumChannels();
	for ( int i = 0; i < c; i++ )
	{
		CChoreoChannel *channel = GetChannel( i );
		if ( !Q_stricmp( channel->GetName(), name ) )
			return channel;
	}

	return NULL;
}
示例#15
0
	int IAudioStream::GetStride() {
		SPADES_MARK_FUNCTION();
		
		int stride;
		switch(GetSampleFormat()){
			case UnsignedByte: stride = 1; break;
			case SignedShort: stride = 2; break;
			case SingleFloat: stride = 4; break;
			default:
				SPInvalidEnum("GetSampleFormat", GetSampleFormat());
		}
		
		return stride * GetNumChannels();
	}
示例#16
0
BOOL CChannels::IsSameFormat(CChannels* psOther)
{
	int				iIndex;
	CChannel*	psSourceChannel;
	CChannel*	psThisChannel;

	if (GetNumChannels() == psOther->GetNumChannels())
	{
		for (iIndex = 0; iIndex < GetNumChannels(); iIndex++)
		{
			psSourceChannel = psOther->GetChannelAtIndex(iIndex);
			psThisChannel = GetChannelAtIndex(iIndex);
			if (!(	(psSourceChannel->eType == psThisChannel->eType) &&
					(psSourceChannel->iChannel == psThisChannel->iChannel) &&
					(psSourceChannel->bReverse == psThisChannel->bReverse)))
			{
				return FALSE;
			}
		}
		return TRUE;
	}
	return FALSE;
}
示例#17
0
// Check which channels contain note data. maxRemoveCount specified how many empty channels are reported at max.
void CModDoc::CheckUsedChannels(std::vector<bool> &usedMask, CHANNELINDEX maxRemoveCount) const
//---------------------------------------------------------------------------------------------
{
	// Checking for unused channels
	CHANNELINDEX chn = GetNumChannels();
	usedMask.assign(chn, true);
	while(chn-- > 0)
	{
		if(IsChannelUnused(chn))
		{
			usedMask[chn] = false;
			// Found enough empty channels yet?
			if((--maxRemoveCount) == 0) break;
		}
	}
}
示例#18
0
bool CPattern::Shrink()
//---------------------
{
	if (!m_ModCommands
		|| m_Rows < GetSoundFile().GetModSpecifications().patternRowsMin * 2)
	{
		return false;
	}

	m_Rows /= 2;
	const CHANNELINDEX nChns = GetNumChannels();

	for(ROWINDEX y = 0; y < m_Rows; y++)
	{
		const PatternRow srcRow = GetRow(y * 2);
		const PatternRow nextSrcRow = GetRow(y * 2 + 1);
		PatternRow destRow = GetRow(y);

		for(CHANNELINDEX x = 0; x < nChns; x++)
		{
			const ModCommand &src = srcRow[x];
			const ModCommand &srcNext = nextSrcRow[x];
			ModCommand &dest = destRow[x];
			dest = src;

			if(dest.note == NOTE_NONE && !dest.instr)
			{
				// Fill in data from next row if field is empty
				dest.note = srcNext.note;
				dest.instr = srcNext.instr;
				if(srcNext.volcmd != VOLCMD_NONE)
				{
					dest.volcmd = srcNext.volcmd;
					dest.vol = srcNext.vol;
				}
				if(dest.command == CMD_NONE)
				{
					dest.command = srcNext.command;
					dest.param = srcNext.param;
				}
			}
		}
	}

	return true;
}
示例#19
0
// Check if there is any note data on a given row.
bool CPattern::IsEmptyRow(ROWINDEX row) const
//-------------------------------------------
{
	if(m_ModCommands == nullptr || !IsValidRow(row))
	{
		return true;
	}

	PatternRow data = GetRow(row);
	for(CHANNELINDEX chn = 0; chn < GetNumChannels(); chn++, data++)
	{
		if(!data->IsEmpty())
		{
			return false;
		}
	}
	return true;
}
StkFrames& NxSoundMediaFileVSTi::Update( StkFrames& Frame ) {

	if(!Frame.size()) Frame.resize( SND_BUFFER_SIZE, GetNumChannels() );

	if( isMuted() || isStopped() ) {

		for ( unsigned int i=0; i < Frame.size(); i++ ){ 
			Frame[i] = 0.0f;
		} 
		return Frame;
	}

	if( VSTInstrument ){

		VstInt32 numinputs = VSTInstrument->GetNumInputs() ;
		VstInt32 numoutputs = VSTInstrument->GetNumOutputs() ;

		if(( VSTInstrument->GetEffect()->flags & effFlagsCanReplacing) != 0) {

			try {
				VSTInstrument->GetEffect()->processReplacing (VSTInstrument->GetEffect(), NULL , outBufs , VSTInstrument->GetBlockSize() );
			}
            catch (...) {
				Log( "NxSound : Error processing NxSoundMediaFileVSTi::Update" );
			}

		 

			for ( unsigned int i=0; i< VSTInstrument->GetBlockSize() ; i++ ){
				float * buffer = outBufs[0];//VSTInstrument->GetOutputBuffer(0) ;
				Frame( i , 0 ) = buffer[i]  ;
			} 

			for ( unsigned int i=0; i< VSTInstrument->GetBlockSize() ; i++ ){
				float * buffer = outBufs[1];//VSTInstrument->GetOutputBuffer(1) ;
				Frame( i , 1 ) = buffer[i] ;
			} 
		}
	}

	return Frame ;
}
示例#21
0
void ImageData::ResizeImage(
    const cv::Size& new_size,
    const ResizeInterpolationMethod interpolation_method) {

  // Undefined behavior if image is empty.
  CHECK(!channels_.empty()) << "Cannot resize an empty image.";
  CHECK_GT(new_size.width, 0) << "Images must have a positive width.";
  CHECK_GT(new_size.height, 0) << "Images must have a positive height.";

  int opencv_interpolation_method = 0;
  switch (interpolation_method) {
    case INTERPOLATE_ADDITIVE:
      // Custom implementation (not in OpenCV).
      image_size_ = ResizeAdditiveInterpolation(new_size, &channels_);
      return;
      break;
    case INTERPOLATE_LINEAR:
      opencv_interpolation_method = cv::INTER_LINEAR;
      break;
    case INTERPOLATE_CUBIC:
      opencv_interpolation_method = cv::INTER_CUBIC;
      break;
    case INTERPOLATE_NEAREST:
    default:
      opencv_interpolation_method = cv::INTER_NEAREST;
      break;
  }

  const int num_image_channels = GetNumChannels();
  for (int i = 0; i < num_image_channels; ++i) {
    cv::Mat scaled_image;
    cv::resize(
        channels_[i],   // Source image.
        scaled_image,   // Dest image.
        new_size,       // Desired image size.
        0,              // Set x, y scale to 0 to use the given Size instead.
        0,
        opencv_interpolation_method);
    channels_[i] = scaled_image;
  }
  image_size_ = new_size;
}
示例#22
0
bool CPattern::AllocatePattern(ROWINDEX rows)
//-------------------------------------------
{
	ModCommand *m = m_ModCommands;
	if(m != nullptr && rows == GetNumRows())
	{
		// Re-use allocated memory
		ClearCommands();
		m_ModCommands = nullptr;
	} else
	{
		m = AllocatePattern(rows, GetNumChannels());
		if(m == nullptr)
		{
			return false;
		}
	}
	Deallocate();
	m_ModCommands = m;
	m_Rows = rows;
	return true;
}
示例#23
0
void CChoreoActor::SaveToBuffer( CUtlBuffer& buf, CChoreoScene *pScene )
{
	int i, c;
	buf.PutString( GetName() );

	c = GetNumChannels();
	buf.PutShort( c );
	for ( i = 0; i < c; i++ )
	{
		CChoreoChannel *channel = GetChannel( i );
		Assert( channel );
		channel->SaveToBuffer( buf, pScene );
	}

	/*
	if ( Q_strlen( a->GetFacePoserModelName() ) > 0 )
	{
		FilePrintf( buf, level + 1, "faceposermodel \"%s\"\n", a->GetFacePoserModelName() );
	}
	*/
	buf.PutChar( GetActive() ? 1 : 0 );
}
示例#24
0
// Check if a given channel contains note data.
bool CModDoc::IsChannelUnused(CHANNELINDEX nChn) const
//----------------------------------------------------
{
	const CHANNELINDEX nChannels = GetNumChannels();
	if(nChn >= nChannels)
	{
		return true;
	}
	for(PATTERNINDEX nPat = 0; nPat < m_SndFile.Patterns.Size(); nPat++)
	{
		if(m_SndFile.Patterns.IsValidPat(nPat))
		{
			const ModCommand *p = m_SndFile.Patterns[nPat] + nChn;
			for(ROWINDEX nRow = m_SndFile.Patterns[nPat].GetNumRows(); nRow > 0; nRow--, p += nChannels)
			{
				if(!p->IsEmpty())
				{
					return false;
				}
			}
		}
	}
	return true;
}
示例#25
0
OPENMPT_NAMESPACE_BEGIN


#pragma warning(disable:4244) //"conversion from 'type1' to 'type2', possible loss of data"


	// Change the number of channels.
// Return true on success.
bool CModDoc::ChangeNumChannels(CHANNELINDEX nNewChannels, const bool showCancelInRemoveDlg)
//------------------------------------------------------------------------------------------
{
	const CHANNELINDEX maxChans = m_SndFile.GetModSpecifications().channelsMax;

	if (nNewChannels > maxChans)
	{
		CString error;
		error.Format("Error: Max number of channels for this file type is %d", maxChans);
		Reporting::Warning(error);
		return false;
	}

	if (nNewChannels == GetNumChannels()) return false;

	if (nNewChannels < GetNumChannels())
	{
		// Remove channels
		UINT nChnToRemove = 0;
		CHANNELINDEX nFound = 0;

		//nNewChannels = 0 means user can choose how many channels to remove
		if(nNewChannels > 0)
		{
			nChnToRemove = GetNumChannels() - nNewChannels;
			nFound = nChnToRemove;
		} else
		{
			nChnToRemove = 0;
			nFound = GetNumChannels();
		}
		
		CRemoveChannelsDlg rem(m_SndFile, nChnToRemove, showCancelInRemoveDlg);
		CheckUsedChannels(rem.m_bKeepMask, nFound);
		if (rem.DoModal() != IDOK) return false;

		// Removing selected channels
		return RemoveChannels(rem.m_bKeepMask, true);
	} else
	{
		// Increasing number of channels
		BeginWaitCursor();
		std::vector<CHANNELINDEX> channels(nNewChannels, CHANNELINDEX_INVALID);
		for(CHANNELINDEX nChn = 0; nChn < GetNumChannels(); nChn++)
		{
			channels[nChn] = nChn;
		}

		const bool success = (ReArrangeChannels(channels) == nNewChannels);
		if(success)
		{
			SetModified();
			UpdateAllViews(nullptr, UpdateHint().ModType());
		}
		EndWaitCursor();
		return success;
	}
}
示例#26
0
// Base code for adding, removing, moving and duplicating channels. Returns new number of channels on success, CHANNELINDEX_INVALID otherwise.
// The new channel vector can contain CHANNELINDEX_INVALID for adding new (empty) channels.
CHANNELINDEX CModDoc::ReArrangeChannels(const std::vector<CHANNELINDEX> &newOrder, const bool createUndoPoint)
//------------------------------------------------------------------------------------------------------------
{
	//newOrder[i] tells which current channel should be placed to i:th position in
	//the new order, or if i is not an index of current channels, then new channel is
	//added to position i. If index of some current channel is missing from the
	//newOrder-vector, then the channel gets removed.

	const CHANNELINDEX nRemainingChannels = static_cast<CHANNELINDEX>(newOrder.size());

	if(nRemainingChannels > m_SndFile.GetModSpecifications().channelsMax || nRemainingChannels < m_SndFile.GetModSpecifications().channelsMin)
	{
		CString str;
		str.Format(_T("Can't apply change: Number of channels should be between %u and %u."), m_SndFile.GetModSpecifications().channelsMin, m_SndFile.GetModSpecifications().channelsMax);
		Reporting::Error(str , "Rearrange Channels");
		return CHANNELINDEX_INVALID;
	}

	if(m_SndFile.Patterns.Size() == 0)
	{
		// Nothing to do
		return GetNumChannels();
	}

	CriticalSection cs;
	if(createUndoPoint)
	{
		PrepareUndoForAllPatterns(true, "Rearrange Channels");
	}

	for(PATTERNINDEX nPat = 0; nPat < m_SndFile.Patterns.Size(); nPat++) 
	{
		if(m_SndFile.Patterns.IsValidPat(nPat))
		{
			ModCommand *oldPatData = m_SndFile.Patterns[nPat];
			ModCommand *newPatData = CPattern::AllocatePattern(m_SndFile.Patterns[nPat].GetNumRows(), nRemainingChannels);
			if(!newPatData)
			{
				cs.Leave();
				Reporting::Error("ERROR: Pattern allocation failed in ReArrangeChannels(...)");
				return CHANNELINDEX_INVALID;
			}
			ModCommand *tmpdest = newPatData;
			for(ROWINDEX nRow = 0; nRow < m_SndFile.Patterns[nPat].GetNumRows(); nRow++) //Scrolling rows
			{
				for(CHANNELINDEX nChn = 0; nChn < nRemainingChannels; nChn++, tmpdest++) //Scrolling channels.
				{
					if(newOrder[nChn] < GetNumChannels()) //Case: getting old channel to the new channel order.
						*tmpdest = *m_SndFile.Patterns[nPat].GetpModCommand(nRow, newOrder[nChn]);
					else //Case: figure newOrder[k] is not the index of any current channel, so adding a new channel.
						*tmpdest = ModCommand::Empty();

				}
			}
			m_SndFile.Patterns[nPat] = newPatData;
			CPattern::FreePattern(oldPatData);
		}
	}

	std::vector<ModChannel> chns(MAX_CHANNELS);
	std::vector<ModChannelSettings> settings(MAX_BASECHANNELS);
	std::vector<BYTE> recordStates(GetNumChannels(), 0);
	std::vector<bool> chnMutePendings(GetNumChannels(), false);

	for(CHANNELINDEX nChn = 0; nChn < GetNumChannels(); nChn++)
	{
		settings[nChn] = m_SndFile.ChnSettings[nChn];
		chns[nChn] = m_SndFile.m_PlayState.Chn[nChn];
		recordStates[nChn] = IsChannelRecord(nChn);
		chnMutePendings[nChn] = m_SndFile.m_bChannelMuteTogglePending[nChn];
	}

	ReinitRecordState();

	for(CHANNELINDEX nChn = 0; nChn < nRemainingChannels; nChn++)
	{
		if(newOrder[nChn] < GetNumChannels())
		{
			m_SndFile.ChnSettings[nChn] = settings[newOrder[nChn]];
			m_SndFile.m_PlayState.Chn[nChn] = chns[newOrder[nChn]];
			if(chns[newOrder[nChn]].nMasterChn > 0 && chns[newOrder[nChn]].nMasterChn <= nRemainingChannels)
			{
				m_SndFile.m_PlayState.Chn[nChn].nMasterChn = newOrder[chns[newOrder[nChn]].nMasterChn - 1] + 1;
			}
			if(recordStates[newOrder[nChn]] == 1) Record1Channel(nChn, true);
			if(recordStates[newOrder[nChn]] == 2) Record2Channel(nChn, true);
			m_SndFile.m_bChannelMuteTogglePending[nChn] = chnMutePendings[newOrder[nChn]];
		} else
		{
			m_SndFile.InitChannel(nChn);
		}
	}
	// Reset MOD panning (won't affect other module formats)
	m_SndFile.SetupMODPanning();

	m_SndFile.m_nChannels = nRemainingChannels;

	// Reset removed channels. Most notably, clear the channel name.
	for(CHANNELINDEX nChn = GetNumChannels(); nChn < MAX_BASECHANNELS; nChn++)
	{
		m_SndFile.InitChannel(nChn);
	}

	return GetNumChannels();
}
示例#27
0
void OmniMapQuartz::init()
{

	std::string setLuaDir = "LuaSupportDir = \"";
	setLuaDir.append(luaSupportDir);
	setLuaDir.append("\"");
	doWireframe = false;
	size_t index = 0;
	while ((index = setLuaDir.find("\\", index)) != std::string::npos)
	{
		setLuaDir.replace(index, 1, "/");
		index++;
	}

	ScriptingEngine->RunString(setLuaDir.c_str());
	ScriptingEngine->RunScript(StartUpScript);
#ifdef notdef
	flatScreen->access.SetValue("Screen_ApexDirection.x", 
		this->GetScreenShape(0)->access.GetNumber("Dome_ApexDirection.x"));
	flatScreen->access.SetValue("Screen_ApexDirection.y", 
		this->GetScreenShape(0)->access.GetNumber("Dome_ApexDirection.y"));
	flatScreen->access.SetValue("Screen_ApexDirection.z", 
		this->GetScreenShape(0)->access.GetNumber("Dome_ApexDirection.z"));
	//flatScreen->access.SetValue("Screen_tesselation", 5);

	flatScreen->CreateGeometry();
	ScreenRendererBase *flatScreenRenderer = ScreenRendererFactory.Create_ScreenRenderer("OGL");
	flatScreen->SetRenderer(flatScreenRenderer);
#endif
	
	

#ifdef NOTNOW
	assert(checkGLError() && "Error: ScriptingEngine->RunScript(StartUpScript);");

	shaders = new OmniMap_Shader();

	assert(checkGLError() && "Error: shaders = new OmniMap_Shader();");

	
	//if(StencilMask_filename)
		//((OmniMap_Shader *)shaders)->StencilMask_Load(StencilMask_filename); // the final mask needs to be done before the shader is compiled....

	if (vertexShaderFilename[0] != '\0' && fragmentShaderFilename[0] != '\0')
	{
		std::string vertShader = luaSupportDir;
		std::string fragShader = luaSupportDir;
		vertShader.append(vertexShaderFilename);
		fragShader.append(fragmentShaderFilename);
		shaders->setShadersFilenames(vertShader.c_str(), fragShader.c_str());
	}

	char prelude[512];
	sprintf(prelude, "// Start Header: automatically generated by Omnimap\n#define MaxChannels %d\n%s\n// End Header\n\n", GetNumChannels(),StencilMask_filename?"#define STENCILMASK_ENABLE":"");
	std::string preludeStr = prelude;
	//shaders->setShadersPrelude(preludeStr.c_str(), preludeStr.c_str());
	shaders->init();

	this->LoadBGTexture();
	
#endif
	LogSystem()->ReportMessage("------------OMNIMAP LOADED DOWN----------------");
	LogSystem()->ReportMessage("glViewportsettings %f %f %f %f",glViewportsettings0,glViewportsettings1,glViewportsettings2,glViewportsettings3);
	LogSystem()->ReportMessage("GL_STATE_CLEAR_AT_STARTFRAME, GL_STATE_glDisable_GL_DEPTH_TEST,GL_STATE_glDepthMask_FALSE %d %d %d",	GL_STATE_CLEAR_AT_STARTFRAME, 
		GL_STATE_glDisable_GL_DEPTH_TEST,GL_STATE_glDepthMask_FALSE );
	LogSystem()->ReportMessage("width %d",		resWidth);
	LogSystem()->ReportMessage("height %d",		resHeight);
	//LogSystem()->ReportMessage("fontname %s",strFont);
	//LogSystem()->ReportMessage("fontsize %f",font_size);
	LogSystem()->ReportMessage("displayHUD  %d",displayHUD );
	LogSystem()->ReportMessage("clear color %f %f %f %f",clearcolor_r,clearcolor_g,clearcolor_b,clearcolor_a );
	LogSystem()->ReportMessage("AudiencePosition %f %f %f\n",AudiencePosition.x,AudiencePosition.y,AudiencePosition.z);
	LogSystem()->ReportMessage("ProjectorPosition.pos %f %f %f\n",ProjectorPosition.pos.x,ProjectorPosition.pos.y,ProjectorPosition.pos.z);
	LogSystem()->ReportMessage("ProjectorPosition.headsUp %f %f %f\n",ProjectorPosition.headsUp.x,ProjectorPosition.headsUp.y,ProjectorPosition.headsUp.z);
	LogSystem()->ReportMessage("ProjectorPosition.lookAtpos %f %f %f\n",ProjectorPosition.lookAtpos.x,ProjectorPosition.lookAtpos.y,ProjectorPosition.lookAtpos.z);
	LogSystem()->ReportMessage("startupscript : %s",StartUpScript);
	LogSystem()->ReportMessage("------------------------------");

}
示例#28
0
bool CSoundFile::ReadDIGI(FileReader &file, ModLoadingFlags loadFlags)
//--------------------------------------------------------------------
{
	file.Rewind();

	DIGIFileHeader fileHeader;
	if(!file.ReadConvertEndianness(fileHeader)
		|| memcmp(fileHeader.signature, "DIGI Booster module\0", 20)
		|| !fileHeader.numChannels
		|| fileHeader.numChannels > 8
		|| fileHeader.lastOrdIndex > 127)
	{
		return false;
	} else if(loadFlags == onlyVerifyHeader)
	{
		return true;
	}

	// Globals
	InitializeGlobals();
	InitializeChannels();

	m_nType = MOD_TYPE_DIGI;
	m_nChannels = fileHeader.numChannels;
	m_nSamples = 31;
	m_nSamplePreAmp = 256 / m_nChannels;
	madeWithTracker = mpt::String::Print("Digi Booster %1.%2", fileHeader.versionInt >> 4, fileHeader.versionInt & 0x0F);

	Order.ReadFromArray(fileHeader.orders, fileHeader.lastOrdIndex + 1);

	// Read sample headers
	for(SAMPLEINDEX smp = 0; smp < 31; smp++)
	{
		ModSample &sample = Samples[smp + 1];
		sample.Initialize(MOD_TYPE_MOD);
		sample.nLength = fileHeader.smpLength[smp];
		sample.nLoopStart = fileHeader.smpLoopStart[smp];
		sample.nLoopEnd = sample.nLoopStart + fileHeader.smpLoopLength[smp];
		if(fileHeader.smpLoopLength[smp])
		{
			sample.uFlags.set(CHN_LOOP);
		}
		sample.SanitizeLoops();
	
		sample.nVolume = std::min(fileHeader.smpVolume[smp], uint8(64)) * 4;
		sample.nFineTune = MOD2XMFineTune(fileHeader.smpFinetune[smp]);
	}

	// Read song + sample names
	file.ReadString<mpt::String::maybeNullTerminated>(songName, 32);
	for(SAMPLEINDEX smp = 1; smp <= 31; smp++)
	{
		file.ReadString<mpt::String::maybeNullTerminated>(m_szNames[smp], 30);
	}

	for(PATTERNINDEX pat = 0; pat <= fileHeader.lastPatIndex; pat++)
	{
		FileReader patternChunk;
		if(fileHeader.packEnable)
		{
			patternChunk = file.ReadChunk(file.ReadUint16BE());
		} else
		{
			patternChunk = file.ReadChunk(4 * 64 * GetNumChannels());
		}

		if(!(loadFlags & loadPatternData) || Patterns.Insert(pat, 64))
		{
			continue;
		}

		if(fileHeader.packEnable)
		{
			std::vector<uint8> eventMask;
			patternChunk.ReadVector(eventMask, 64);

			// Compressed patterns are stored in row-major order...
			for(ROWINDEX row = 0; row < 64; row++)
			{
				PatternRow patRow = Patterns[pat].GetRow(row);
				uint8 bit = 0x80;
				for(CHANNELINDEX chn = 0; chn < GetNumChannels(); chn++, bit >>= 1)
				{
					if(eventMask[row] & bit)
					{
						ModCommand &m = patRow[chn];
						ReadDIGIPatternEntry(patternChunk, m, *this);
					}
				}
			}
		} else
		{
			// ...but uncompressed patterns are stored in column-major order. WTF!
			for(CHANNELINDEX chn = 0; chn < GetNumChannels(); chn++)
示例#29
0
void OmniMapD3D::init()
{
  EH_DECLARE;

  std::string setLuaDir = "LuaSupportDir = \"";
  setLuaDir.append(luaSupportDir);
  setLuaDir.append("\"");
  size_t index = 0;
  while ((index = setLuaDir.find("\\", index)) != std::string::npos)
  {
    setLuaDir.replace(index, 1, "/");
    index++;
  }

  EH_Zero(ScriptingEngine->RunString(setLuaDir.c_str()));
  EH_Zero(ScriptingEngine->RunScript(StartUpScript));

  EH_Ptr(shaders = new OmniMapShaderD3D(d3dDevice));

  ((OmniMapShaderD3D *)shaders)->CobraWarpWithTrueDimension = (this)->CobraWarpWithTrueDimension;


  if(CobraWarpWithTrueDimension>0){
    EH_Log("CobraWarpWithTrueDimension (0 is off 1 is Warp with TrueDimension On, 2 is Warp with TrueDimension off ) = %d",CobraWarpWithTrueDimension);
  }
  if (fxShaderFilename[0] != '\0') {
    EH_Log("loading shader %s",fxShaderFilename);
    std::string vertexShaderFilename = luaSupportDir;
    vertexShaderFilename.append(fxShaderFilename);
    ((OmniMapShaderD3D *) shaders)->setShadersFilenames(vertexShaderFilename.c_str(), NULL);
  }
  ((OmniMapShaderD3D *) shaders)->setNumChannels(GetNumChannels());
  
  if(StencilMask_filename)
    ((OmniMapShaderD3D *)shaders)->StencilMask_Load(StencilMask_filename); // the final mask needs to be done before the shader is compiled....
  
  shaders->init();

  for (int i = 0; i < GetNumChannels(); i++)
  {
    ((OmniMapChannelD3D *) this->GetChannel(i))->setOMShader((OmniMapShaderD3D *) shaders);
  }

  InitBG();
  EH_Log("------------OMNIMAP LOADED----------------");

  EH_OnError() {
    EH_Log("------------OMNIMAP FAILED TO LOADED----------------");
    if (shaders) { delete ((OmniMapShaderD3D *) shaders); shaders = NULL; }
  }

  EH_Log("glViewportsettings %f %f %f %f",glViewportsettings0,glViewportsettings1,glViewportsettings2,glViewportsettings3);
  EH_Log("GL_STATE_CLEAR_AT_STARTFRAME, GL_STATE_glDisable_GL_DEPTH_TEST,GL_STATE_glDepthMask_FALSE %d %d %d",	GL_STATE_CLEAR_AT_STARTFRAME, GL_STATE_glDisable_GL_DEPTH_TEST,GL_STATE_glDepthMask_FALSE );
  EH_Log("width %d",		resWidth);
  EH_Log("height %d",		resHeight);
  EH_Log("displayHUD  %d",displayHUD );
  EH_Log("clear color %f %f %f %f",clearcolor_r,clearcolor_g,clearcolor_b,clearcolor_a );
  EH_Log("AudiencePosition %f %f %f\n",AudiencePosition.x,AudiencePosition.y,AudiencePosition.z);
  EH_Log("ProjectorPosition.pos %f %f %f\n",ProjectorPosition.pos.x,ProjectorPosition.pos.y,ProjectorPosition.pos.z);
  EH_Log("ProjectorPosition.headsUp %f %f %f\n",ProjectorPosition.headsUp.x,ProjectorPosition.headsUp.y,ProjectorPosition.headsUp.z);
  EH_Log("ProjectorPosition.lookAtpos %f %f %f\n",ProjectorPosition.lookAtpos.x,ProjectorPosition.lookAtpos.y,ProjectorPosition.lookAtpos.z);
  EH_Log("startupscript : %s",StartUpScript);
  EH_Log("------------------------------");
}
ImageData IRLSMapSolver::Solve(const ImageData& initial_estimate) {
  const int num_pixels = GetNumPixels();
  const int num_channels = GetNumChannels();
  const cv::Size image_size = GetImageSize();
  CHECK_EQ(initial_estimate.GetNumPixels(), num_pixels);
  CHECK_EQ(initial_estimate.GetNumChannels(), num_channels);
  CHECK_EQ(initial_estimate.GetImageSize(), image_size);

  // If the split_channels option is set, loop over the channels here and solve
  // them independently. Otherwise, solve all channels at once.
  const int num_channels_per_split =
      solver_options_.split_channels ? 1 : num_channels;
  const int num_solver_rounds = num_channels / num_channels_per_split;
  const int num_data_points = num_channels_per_split * num_pixels;
  if (num_channels_per_split != num_channels) {
    LOG(INFO) << "Splitting up image into " << num_solver_rounds
              << " sections with " << num_channels_per_split
              << " channel(s) in each section.";
  }

  // Scale the option stop criteria parameters based on the number of
  // parameters and strength of the regularizers.
  IRLSMapSolverOptions solver_options_scaled = solver_options_;
  solver_options_scaled.AdjustThresholdsAdaptively(
      num_data_points, GetRegularizationParameterSum());

  if (IsVerbose()) {
    solver_options_scaled.PrintSolverOptions();
  }

  ImageData estimated_image;
  for (int i = 0; i < num_solver_rounds; ++i) {
    if (num_solver_rounds > 1) {
      LOG(INFO) << "Starting solver on image subset #" << (i + 1) << ".";
    }
    const int channel_start = i * num_channels_per_split;
    const int channel_end = channel_start + num_channels_per_split;

    // Copy the initial estimate data (within the appropriate channel range) to
    // the solver's array.
    alglib::real_1d_array solver_data;
    solver_data.setlength(num_data_points);
    for (int channel = 0; channel < num_channels_per_split; ++channel) {
      double* data_ptr = solver_data.getcontent() + (num_pixels * channel);
      const double* channel_ptr = initial_estimate.GetChannelData(
          channel_start + channel);
      std::copy(channel_ptr, channel_ptr + num_pixels, data_ptr);
    }

    // Set up the base objective function (just data term). The regularization
    // term depends on the IRLS weights, so it gets added in the IRLS loop.
    ObjectiveFunction objective_function_data_term_only(num_data_points);
    std::shared_ptr<ObjectiveTerm> data_term(new ObjectiveDataTerm(
        image_model_, observations_, channel_start, channel_end, image_size));
    objective_function_data_term_only.AddTerm(data_term);

    RunIRLSLoop(
        solver_options_scaled,
        objective_function_data_term_only,
        regularizers_,
        image_size,
        channel_start,
        channel_end,
        &solver_data);

    for (int channel = 0; channel < num_channels_per_split; ++channel) {
      const double* data_ptr =
          solver_data.getcontent() + (num_pixels * channel);
      estimated_image.AddChannel(data_ptr, image_size);
    }
  }

  return estimated_image;
}