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


C++ MAD_NCHANNELS函数代码示例

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


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

示例1: mp3_send_pcm

/**
 * Sends the synthesized current frame via decoder_data().
 */
static enum decoder_command
mp3_send_pcm(struct mp3_data *data, unsigned i, unsigned pcm_length)
{
	unsigned max_samples;

	max_samples = sizeof(data->output_buffer) /
		sizeof(data->output_buffer[0]) /
		MAD_NCHANNELS(&(data->frame).header);

	while (i < pcm_length) {
		enum decoder_command cmd;
		unsigned int num_samples = pcm_length - i;
		if (num_samples > max_samples)
			num_samples = max_samples;

		i += num_samples;

		mad_fixed_to_24_buffer(data->output_buffer,
				       &data->synth,
				       i - num_samples, i,
				       MAD_NCHANNELS(&(data->frame).header));
		num_samples *= MAD_NCHANNELS(&(data->frame).header);

		cmd = decoder_data(data->decoder, data->input_stream,
				   data->output_buffer,
				   sizeof(data->output_buffer[0]) * num_samples,
				   data->bit_rate / 1000);
		if (cmd != DECODE_COMMAND_NONE)
			return cmd;
	}

	return DECODE_COMMAND_NONE;
}
开发者ID:Acidburn0zzz,项目名称:mpd,代码行数:36,代码来源:mad_decoder_plugin.c

示例2: mp3_mad_decode

void
mp3_mad_decode (mp3_info_t *info) {
    // copy synthesized samples into readbuffer
    int idx = info->mad_synth.pcm.length-info->buffer.decode_remaining;
    // stereo
    if (MAD_NCHANNELS(&info->mad_frame.header) == 2 && info->info.fmt.channels == 2) {
        while (info->buffer.decode_remaining > 0 && info->buffer.readsize > 0) {
            *((int16_t*)info->buffer.out) = MadFixedToSshort (info->mad_synth.pcm.samples[0][idx]);
            info->buffer.readsize -= 2;
            info->buffer.out += 2;
            *((int16_t*)info->buffer.out) = MadFixedToSshort (info->mad_synth.pcm.samples[1][idx]);
            info->buffer.readsize -= 2;
            info->buffer.out += 2;
            info->buffer.decode_remaining--;
            idx++;
        }
    }
    // mono
    else if (MAD_NCHANNELS(&info->mad_frame.header) == 1 && info->info.fmt.channels == 1){
        while (info->buffer.decode_remaining > 0 && info->buffer.readsize > 0) {
            *((int16_t*)info->buffer.out) = MadFixedToSshort (info->mad_synth.pcm.samples[0][idx]);
            info->buffer.readsize -= 2;
            info->buffer.out += 2;
            info->buffer.decode_remaining--;
            idx++;
        }
    }
    // workaround for bad mp3s that have both mono and stereo frames
    else if (MAD_NCHANNELS(&info->mad_frame.header) == 1 && info->info.fmt.channels == 2) {
        while (info->buffer.decode_remaining > 0 && info->buffer.readsize > 0) {
            int16_t sample = MadFixedToSshort (info->mad_synth.pcm.samples[0][idx]);
            *((int16_t*)info->buffer.out) = sample;
            info->buffer.readsize -= 2;
            info->buffer.out += 2;
            *((int16_t*)info->buffer.out) = sample;
            info->buffer.readsize -= 2;
            info->buffer.out += 2;
            info->buffer.decode_remaining--;
            idx++;
        }
    }
    else if (MAD_NCHANNELS(&info->mad_frame.header) == 2 && info->info.fmt.channels == 1) {
        while (info->buffer.decode_remaining > 0 && info->buffer.readsize > 0) {
            int16_t sample = MadFixedToSshort (info->mad_synth.pcm.samples[0][idx]);
            *((int16_t*)info->buffer.out) = sample;
            info->buffer.readsize -= 2;
            info->buffer.out += 2;
            info->buffer.decode_remaining--;
            idx++;
        }
    }
}
开发者ID:dHRUSHIT,项目名称:deadbeef,代码行数:52,代码来源:mp3_mad.c

示例3: _inStream

Mp3PspStream::Mp3PspStream(Common::SeekableReadStream *inStream, DisposeAfterUse::Flag dispose) :
	_inStream(inStream),
	_disposeAfterUse(dispose),
	_pcmLength(0),
	_posInFrame(0),
	_state(MP3_STATE_INIT),
	_length(0, 1000),
	_sampleRate(0),
	_totalTime(mad_timer_zero) {

	DEBUG_ENTER_FUNC();

	assert(_decoderInit);	// must be initialized by now

	// let's leave the buffer guard -- who knows, it may be good?
	memset(_buf, 0, sizeof(_buf));
	memset(_codecInBuffer, 0, sizeof(_codecInBuffer));

	initStream();	// init needed stuff for the stream

	findValidHeader();	// get a first header so we can read basic stuff

	_sampleRate = _header.samplerate;	// copy it before it gets destroyed
	_stereo = (MAD_NCHANNELS(&_header) == 2);

	while (_state != MP3_STATE_EOS)
		findValidHeader();	// get a first header so we can read basic stuff

	_length = Timestamp(mad_timer_count(_totalTime, MAD_UNITS_MILLISECONDS), getRate());

	deinitStream();

	_state = MP3_STATE_INIT;
}
开发者ID:MatChung,项目名称:scummvm-ps3,代码行数:34,代码来源:mp3.cpp

示例4: mp3_read

static int mp3_read (song_s *song, char *buffer)
{
  static int i;
  static int ret;
  static struct audio_dither dither;
  static char buffer2[BUF_SIZE];
  static char *out_ptr = buffer2;
  static char *out_buf_end = buffer2 + BUF_SIZE;
  mp3_s *mp3 = song->songlib->mp3;

  mad_timer_add (&mp3->timer, mp3->frame.header.duration);
  mad_synth_frame (&mp3->synth, &mp3->frame);
  mp3->elapsed_time = ((float)mad_timer_count (mp3->timer, MAD_UNITS_MILLISECONDS))/1000.0;
  
  for (i = 0; i < mp3->synth.pcm.length; i++) {
    signed int sample;
    sample = (signed int)audio_linear_dither (16, mp3->synth.pcm.samples[0][i], &dither);
   
    *(out_ptr++) = sample & 0xff;
    *(out_ptr++) = sample >> 8;

    if (MAD_NCHANNELS (&(mp3->frame).header) == 2) {
      sample = (signed int) audio_linear_dither (16, mp3->synth.pcm.samples[1][i], &dither);

      *(out_ptr++) = sample & 0xff;
      *(out_ptr++) = sample >> 8;
    }

    if (out_ptr == out_buf_end) {
      memcpy (buffer, buffer2, BUF_SIZE);
      bossao_play_chunk (song, buffer, BUF_SIZE);
      out_ptr = buffer2;
    }
  }
开发者ID:tedkulp,项目名称:bossogg,代码行数:34,代码来源:mp3.c

示例5: memalign

void Mp3Decoder::OpenFile()
{
    GuardPtr = NULL;
    ReadBuffer = (u8 *) memalign(32, SoundBlockSize*SoundBlocks);
    if(!ReadBuffer)
    {
        if(file_fd)
            delete file_fd;
        file_fd = NULL;
        return;
    }

    u8 dummybuff[4096];
    int ret = Read(dummybuff, 4096, 0);
    if(ret <= 0)
    {
        if(file_fd)
            delete file_fd;
        file_fd = NULL;
        return;
    }

    SampleRate = (u32) Frame.header.samplerate;
    Format = ((MAD_NCHANNELS(&Frame.header) == 2) ? VOICE_STEREO_16BIT : VOICE_MONO_16BIT);
    Rewind();
    Decode();
}
开发者ID:SuperrSonic,项目名称:WiiXplorer-SS,代码行数:27,代码来源:Mp3Decoder.cpp

示例6: output_synth_data

int output_synth_data(mpgedit_madbuf_t *ctx)
{
    int i;
    int rsts;

    for(i=0;i<ctx->Synth.pcm.length;i++) {
        signed short    Sample;

        /* Left channel */
        Sample=MadFixedToSshort(ctx->Synth.pcm.samples[0][i]);
        *(ctx->OutputPtr++) = Sample & 0xff;
        *(ctx->OutputPtr++) = Sample >> 8;

        /* Right channel. If the decoded stream is monophonic then
         * the right output channel is the same as the left one.
         */
        if(MAD_NCHANNELS(&ctx->Frame.header)==2) {
            Sample=MadFixedToSshort(ctx->Synth.pcm.samples[1][i]);
            *(ctx->OutputPtr++) = Sample & 0xff;
            *(ctx->OutputPtr++) = Sample >> 8;
        }

        /* Flush the output buffer if it is full. */
        if (ctx->OutputPtr >= ctx->OutputBufferEnd) {
            rsts = fwrite(ctx->OutputBuffer, 1, OUTPUT_BUFFER_SIZE, ctx->outfp);
            if (rsts != OUTPUT_BUFFER_SIZE) {
                fprintf(stderr,"%s: PCM write error (%s).\n",
                        "main" ,strerror(errno));
                return 1;
            }
            ctx->OutputPtr = ctx->OutputBuffer;
        }
    }
开发者ID:gusrc,项目名称:mpgedit,代码行数:33,代码来源:readframes1.c

示例7: mad_synth_frame

/*
 * NAME:	synth->frame()
 * DESCRIPTION:	perform PCM synthesis of frame subband samples
 */
void mad_synth_frame(struct mad_synth *synth, struct mad_frame const *frame) {
    unsigned int nch, ns;
    void (*synth_frame)(struct mad_synth *, struct mad_frame const *,
                        unsigned int, unsigned int);

    nch = MAD_NCHANNELS(&frame->header);
    ns = MAD_NSBSAMPLES(&frame->header);

    synth->pcm.samplerate = frame->header.samplerate;
    synth->pcm.channels = nch;
    synth->pcm.length = 32 * ns;

    synth_frame = synth_full;

    if (frame->options & MAD_OPTION_HALFSAMPLERATE) {
        synth->pcm.samplerate /= 2;
        synth->pcm.length /= 2;

        synth_frame = synth_half;
    }

    synth_frame(synth, frame, nch, ns);

    synth->phase = (synth->phase + ns) % 16;
}
开发者ID:dnwang,项目名称:android_demo,代码行数:29,代码来源:synth.c

示例8: mad_header_cb

static enum mad_flow mad_header_cb(void *blob, const mad_header_t *header) {
    state_t *data = (state_t *)blob;

    data->sample_rate = header->samplerate;
    data->output_channels = MAD_NCHANNELS(header);
    data->output_size += mad_timer_count(header->duration, header->samplerate);
    return MAD_FLOW_IGNORE;
}
开发者ID:tlevine,项目名称:tuneR,代码行数:8,代码来源:readmp3.c

示例9: while

int MP3Stream::readBuffer(int16 *buffer, const int numSamples) {
	int samples = 0;
	// Keep going as long as we have input available
	while (samples < numSamples && _state != MP3_STATE_EOS) {
		const int len = MIN(numSamples, samples + (int)(_synth.pcm.length - _posInFrame) * MAD_NCHANNELS(&_frame.header));
		while (samples < len) {
			*buffer++ = (int16)scale_sample(_synth.pcm.samples[0][_posInFrame]);
			samples++;
			if (MAD_NCHANNELS(&_frame.header) == 2) {
				*buffer++ = (int16)scale_sample(_synth.pcm.samples[1][_posInFrame]);
				samples++;
			}
			_posInFrame++;
		}
		if (_posInFrame >= _synth.pcm.length) {
			// We used up all PCM data in the current frame -- read & decode more
			decodeMP3Data();
		}
	}
	return samples;
}
开发者ID:Templier,项目名称:residual,代码行数:21,代码来源:mp3.cpp

示例10: put_output

static int put_output (char *buf, int buf_len, struct mad_pcm *pcm,
		struct mad_header *header)
{
	unsigned int nsamples;
	mad_fixed_t const *left_ch, *right_ch;
	int olen;

	nsamples = pcm->length;
	left_ch = pcm->samples[0];
	right_ch = pcm->samples[1];
	olen = nsamples * MAD_NCHANNELS (header) * 4;

	if (olen > buf_len) {
		logit ("PCM buffer to small!");
		return 0;
	}
	
	while (nsamples--) {
		long sample0 = round_sample (*left_ch++);
		
		buf[0] = 0;
		buf[1] = sample0;
		buf[2] = sample0 >> 8;
		buf[3] = sample0 >> 16;
		buf += 4;

		if (MAD_NCHANNELS(header) == 2) {
			long sample1;
			
			sample1 = round_sample (*right_ch++);

			buf[0] = 0;
			buf[1] = sample1;
			buf[2] = sample1 >> 8;
			buf[3] = sample1 >> 16;

			buf += 4;
		}
	}
开发者ID:ecthiender,项目名称:mocp-git,代码行数:39,代码来源:mp3.c

示例11: DEBUG_ENTER_FUNC

int Mp3PspStream::readBuffer(int16 *buffer, const int numSamples) {
	DEBUG_ENTER_FUNC();

	int samples = 0;
#ifdef PRINT_BUFFERS
	int16 *debugBuffer = buffer;
#endif

	// Keep going as long as we have input available
	while (samples < numSamples && _state != MP3_STATE_EOS) {
		const int len = MIN(numSamples, samples + (int)(_pcmLength - _posInFrame) * MAD_NCHANNELS(&_header));

		while (samples < len) {
			*buffer++ = _pcmSamples[_posInFrame << 1];
			samples++;
			if (MAD_NCHANNELS(&_header) == 2) {
				*buffer++ = _pcmSamples[(_posInFrame << 1) + 1];
				samples++;
			}
			_posInFrame++;	// always skip an extra sample since ME always outputs stereo
		}

		if (_posInFrame >= _pcmLength) {
			// We used up all PCM data in the current frame -- read & decode more
			decodeMP3Data();
		}
	}

#ifdef PRINT_BUFFERS
		PSP_INFO_PRINT("buffer:\n");
		for (int i = 0; i<numSamples; i++)
			PSP_INFO_PRINT("%d ", debugBuffer[i]);
		PSP_INFO_PRINT("\n\n");
#endif

	return samples;
}
开发者ID:MatChung,项目名称:scummvm-ps3,代码行数:37,代码来源:mp3.cpp

示例12: ASSERT

RageSoundReader_FileReader::OpenResult RageSoundReader_MP3::Open( RageFileBasic *pFile )
{
	m_pFile = pFile;

	mad->filesize = m_pFile->GetFileSize();
	ASSERT( mad->filesize != -1 );

	/* Make sure we can decode at least one frame.  This will also fill in header info. */
	mad->outpos = 0;

	int ret = do_mad_frame_decode();
	switch(ret)
	{
	case 0:
		SetError( "Failed to read any data at all" );
		return OPEN_UNKNOWN_FILE_FORMAT;
	case -1:
		SetError( GetError() + " (not an MP3 stream?)" );
		return OPEN_UNKNOWN_FILE_FORMAT;
	}

	/* Store the bitrate of the frame we just got. */
	if( mad->bitrate == -1 ) /* might have been set by a Xing tag */
		mad->bitrate = mad->Frame.header.bitrate;

	SampleRate = mad->Frame.header.samplerate;
	mad->framelength = mad->Frame.header.duration;
	this->Channels = MAD_NCHANNELS( &mad->Frame.header );

	/* Since we've already decoded a frame, just synth it instead of rewinding
	 * the stream. */
	synth_output();

	if(mad->length == -1)
	{
		/* If vbr and !xing, this is just an estimate. */
		int bps = mad->bitrate / 8;
		float secs = (float)(mad->filesize - mad->header_bytes) / bps;
		mad->length = (int)(secs * 1000.f);
	}

	return OPEN_OK;
}
开发者ID:SamDecrock,项目名称:stepmania5-http-post-scores,代码行数:43,代码来源:RageSoundReader_MP3.cpp

示例13: mad_synth_frame

//extern unsigned char set__;
void mad_synth_frame(struct mad_synth *synth, struct mad_frame /*const*/ *frame)
{
  unsigned int nch, ns;
  static int samplerate=0;
  void (*synth_frame)(struct mad_synth *, struct mad_frame /*const*/ *,
		      unsigned int, unsigned int);

  nch = MAD_NCHANNELS(&frame->header);
  ns  = MAD_NSBSAMPLES(&frame->header);

  synth->pcm.samplerate = frame->header.samplerate;
  
  //--set_dac_sample_rate(synth->pcm.samplerate);
  //while(g_ulFlags!=7);
  
  //if(set__)
  {
    vPortEnterCritical( );
    SoundSetFormat(frame->header.samplerate,16,1);
    //set__=0;
    vPortExitCritical( );
  }
  
  synth->pcm.channels   = nch;
  synth->pcm.length     = 32 * ns;
  samplerate = synth->pcm.samplerate;

  synth_frame = synth_full;

  if (frame->options & MAD_OPTION_HALFSAMPLERATE) {
    synth->pcm.samplerate /= 2;
    synth->pcm.length     /= 2;
    //--set_dac_sample_rate(synth->pcm.samplerate);
    vPortEnterCritical( );
    SoundSetFormat(frame->header.samplerate,16,1);
    vPortExitCritical( );
    synth_frame = synth_half;
  }

  synth_frame(synth, frame, nch, ns);
  synth->phase = (synth->phase + ns) % 16;
}
开发者ID:KYHuang,项目名称:arm-mp3-player,代码行数:43,代码来源:synth.c

示例14: Open

bool MADDecoder::Open(FileSpecifier &File)
{
	if (!File.Open(file)) return false;

	file_done = false;

	if (DecodeFrame())
	{
		stereo = (MAD_NCHANNELS(&Frame.header) == 2);
		bytes_per_frame = 2 * (stereo ? 2 : 1);
		rate = Frame.header.samplerate;

		sample = 0;
		return true;
	}
	else
	{
		return false;
	}
}
开发者ID:Aleph-One-Marathon,项目名称:alephone-dingoo,代码行数:20,代码来源:MADDecoder.cpp

示例15: mp3_decode

static void
mp3_decode(struct decoder *decoder, struct input_stream *input_stream)
{
	struct mp3_data data;
	GError *error = NULL;
	struct tag *tag = NULL;
	struct audio_format audio_format;

	if (!mp3_open(input_stream, &data, decoder, &tag)) {
		if (decoder_get_command(decoder) == DECODE_COMMAND_NONE)
			g_warning
			    ("Input does not appear to be a mp3 bit stream.\n");
		return;
	}

	if (!audio_format_init_checked(&audio_format,
				       data.frame.header.samplerate,
				       SAMPLE_FORMAT_S24_P32,
				       MAD_NCHANNELS(&data.frame.header),
				       &error)) {
		g_warning("%s", error->message);
		g_error_free(error);

		if (tag != NULL)
			tag_free(tag);
		mp3_data_finish(&data);
		return;
	}

	decoder_initialized(decoder, &audio_format,
			    data.input_stream->seekable, data.total_time);

	if (tag != NULL) {
		decoder_tag(decoder, input_stream, tag);
		tag_free(tag);
	}

	while (mp3_read(&data)) ;

	mp3_data_finish(&data);
}
开发者ID:Acidburn0zzz,项目名称:mpd,代码行数:41,代码来源:mad_decoder_plugin.c


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