The International Simutrans Forum

 

Author Topic: r100.0: Sound frequency: slightly wrong, half inflexible, no conversion  (Read 2997 times)

0 Members and 1 Guest are viewing this topic.

GreaseMonkey

  • Guest
It's possible to play various types of music other than MIDI if you use SDL_mixer. However, if you attempt to play a WAV, OGG, MP3, or any audio format supported by SDL_mixer, it plays it at simutrans' sound frequency and not the audio frequency. I know this is somewhat unexpected, and I don't expect it fixed, but when I downsampled a tune, I noticed something odd...

Are you sure you meant to use 22500Hz? Because the closest standard frequency is 22050Hz.

Code: [Select]
[ben@roflcopter ~/Desktop/FOLDERS/simutrans]$ grep 22500 */*
music/sdl_midi.cc:                      Mix_OpenAudio(22500, AUDIO_S16SYS, 2, 1024);
sound/sdl_mixer_sound.cc:               int freq = 22500;
sound/sdl_sound.cc:             desired.freq = 22500;

By the way, if you're afraid of breaking stuff, don't worry too much about it. If you get a frequency converter set up though, or the sounds happen to be 22050Hz, then I recommend you tweak those.
Also, I'm pretty sure some cards don't particularly like frequencies they're not used to, but I'm also pretty sure that most OSes convert the frequencies anyway (I think mine works best with 48000Hz or something).

ALSO: Why does sdl_midi use a static frequency? That needs to be fixed.

EDIT: By the way, I am running FreeBSD, not Linux, although they are quite similar.

Offline prissi

  • Developer
  • Administrator
  • *
  • Posts: 9127
  • Languages: De,EN,JP
Re: r100.0: Sound frequency: slightly wrong, half inflexible, no conversion
« Reply #1 on: September 09, 2008, 09:50:12 AM »
Actually, the frequency is supposed to be 22050. Honestly, this is mostly to save computer power, as rendering midi is very CPU expensive. And most of all sound effects are 11025 kHz mono to save disk space for the distribution.

The SDL_midi is not made by me, thus I have not really an idea, what you mean by
Quote
ALSO: Why does sdl_midi use a static frequency? That needs to be fixed.

Offline kierongreen

  • Dev Team, Coder/patcher
  • Devotee
  • *
  • Posts: 2256
Re: r100.0: Sound frequency: slightly wrong, half inflexible, no conversion
« Reply #2 on: September 09, 2008, 08:34:04 PM »
The code uses a fixed frequency because SDL_Mixer needs a frequency to use. As prissi said, higher frequency needs more cpu power, hence using 22050kHz (and yes 22500 was a typo). Seem to remember the frequency value is needed when initialising the sound system so it couldn't be changed for each music file, however I'm sure it'd be possible to add a configuration option to change this frequency.
Unfortunately the system I'm using at the moment doesn't seem to want to run sdl_mixer so I can't test sound support currently.