Пример #1
0
static void SetShortSample(Sound *s, long i, int c, short val) {
  if (i >= Snack_GetLength(s) || s->storeType != SOUND_IN_MEMORY)
    return;
  i = i * Snack_GetNumChannels(s) + c;
  if (Snack_GetSampleEncoding(s) == LIN8) {
    val /= 256;
  }
  FSAMPLE(s, i) = (float) val;
}
Пример #2
0
static short GetShortSample(Sound *s, long i, int c) {
  short res = 0;
  if (i >= Snack_GetLength(s) || s->storeType == SOUND_IN_CHANNEL)
    return 0;
  i = i * Snack_GetNumChannels(s) + c;
  if (s->storeType == SOUND_IN_MEMORY) {
    res = (short) FSAMPLE(s, i);
  } else {
    if (s->linkInfo.linkCh == NULL) {
      OpenLinkedFile(s, &s->linkInfo);
    }
    res = (short) GetSample(&s->linkInfo, i);
  }
  if (Snack_GetSampleEncoding(s) == LIN8) {
    res <<= 8;
  }
  return res;
}
static int GetSndHeader(Sound *s, Tcl_Interp *interp, Tcl_Channel ch, Tcl_Obj *obj, char *buf)
{
	/* fprintf(stderr, "GetSndHeader\n"); */
	if (obj != NULL)
	{
		Tcl_AppendResult(interp, "'data' subcommand forbidden for SNDFILE format", NULL);
		if (ch)
		{
			sf_close((SNDFILE *)ch);
		}
		return TCL_ERROR;
	}

	if (Snack_GetDebugFlag(s) > 2)
	{
		Snack_WriteLog("    Reading SNDFILE header\n");
	}

	SF_INFO file_info;
	int ret = sf_command ((SNDFILE*) ch, SFC_GET_CURRENT_SF_INFO, &file_info, sizeof(SF_INFO));
	Snack_SetSampleRate(s, file_info.samplerate);
	if (Snack_GetDebugFlag(s) > 3) {
		Snack_WriteLogInt("      Setting rate", Snack_GetSampleRate(s));
	}
	Snack_SetNumChannels(s, file_info.channels);
	if (Snack_GetDebugFlag(s) > 3) {
		Snack_WriteLogInt("      Setting channels", Snack_GetNumChannels(s));
	}

	switch(file_info.format & SF_FORMAT_SUBMASK)
	{
	case SF_FORMAT_PCM_S8:
	case SF_FORMAT_PCM_U8:
		Snack_SetBytesPerSample(s, 1);
		Snack_SetSampleEncoding(s, LIN8);
		break;
	case SF_FORMAT_PCM_16:
		Snack_SetBytesPerSample(s, 2);
		Snack_SetSampleEncoding(s, LIN16);
		break;
	case SF_FORMAT_PCM_24:
		Snack_SetBytesPerSample(s, 3);
		Snack_SetSampleEncoding(s, LIN24);
		break;
	case SF_FORMAT_PCM_32:
		Snack_SetBytesPerSample(s, 4);
		Snack_SetSampleEncoding(s, LIN32);
		break;
	case SF_FORMAT_FLOAT:
		Snack_SetBytesPerSample(s, 4);
		Snack_SetSampleEncoding(s, SNACK_FLOAT);
		break;
	case SF_FORMAT_DOUBLE:
		Snack_SetBytesPerSample(s, 8);
		Snack_SetSampleEncoding(s, SNACK_DOUBLE);
		break;
	case SF_FORMAT_ULAW:
		Snack_SetBytesPerSample(s, 1);
		Snack_SetSampleEncoding(s, MULAW);
		break;
	case SF_FORMAT_ALAW:
		Snack_SetBytesPerSample(s, 1);
		Snack_SetSampleEncoding(s, ALAW);
		break;
	case SF_FORMAT_IMA_ADPCM:
	case SF_FORMAT_MS_ADPCM:
	case SF_FORMAT_GSM610:
	case SF_FORMAT_VOX_ADPCM:
	case SF_FORMAT_G721_32:
	case SF_FORMAT_G723_24:
	case SF_FORMAT_G723_40:
	case SF_FORMAT_DWVW_12:
	case SF_FORMAT_DWVW_16:
	case SF_FORMAT_DWVW_24:
	case SF_FORMAT_DWVW_N:
	case SF_FORMAT_DPCM_8:
	case SF_FORMAT_DPCM_16:
	case SF_FORMAT_VORBIS:
	default:
		/* fprintf(stderr, "GetSndHeader: format defaults\n"); */
		Snack_SetBytesPerSample(s, 4);
		Snack_SetSampleEncoding(s, SNACK_FLOAT);
		/* LIN16 */
		/* ALAW */
		/* MULAW */
		/* LIN8OFFSET */
		/* LIN8 */
		/* LIN24 */
		/* LIN32 */
		/* SNACK_FLOAT */
		/* SNACK_DOUBLE */
		/* LIN24PACKED */
		break;
	}
	Snack_SetLength(s, file_info.frames);
	Snack_SetHeaderSize(s, 0 /* ?? HEADERSIZE */);

	return TCL_OK;
}