Playing streaming ogg music

From C4 Engine Wiki

Jump to: navigation, search

Contents

Ogg music

Ogg files which contain music encoded with the Vorbis codec provide better sound quality than MP3s encoded at identical bitrates. The official C4 Engine package only supports 16-bit uncompressed .wav files and ADPCM .wav files, which have a 4:1 compression. However, for many songs, 48kbps (30:1) provides acceptable results.

The Ogg container file format, and the Vorbis codec file format are both published as free, open standards.

C4ogg

In this thread, Szymon Połom released C4ogg, which allows C4 to play ogg files.

Downloads

C4ogg uses Ogg 1.1.3 and Vorbis 1.2.0. These packages can be downloaded here:

libvorbis-1.2.0.tar.gz

libogg-1.1.3.tar.gz

Note: you need to have access to the forums' Licensed User Area to download these files:

C4ogg documentation

C4ogg files

The contents of C4ogg.zip

The zip file is organized for Windows:

  • The root folder contains the following dynamic DLLs: ogg.dll, vorbis.dll, and vorbisfile.dll. These files should be placed in the root folder where C4.exe and Game.dll are located.
  • The directory "./VisualStudio/C4/Engine/" contains .lib versions of those files.
  • The directory "./EngineCode/" contains the six C4ogg source code files, as well as source code used by Ogg and Vorbis. The code has been edited so that you don't need to put the Ogg/Vorbis code in a separate location or set up paths to include. But you do need to edit the Engine project's Input in the Linker section. In the "Additional Dependencies" section add the following .lib files to the list: ogg.lib vorbis.lib vorbisfile.lib

Playing Ogg music in the game's menus

MGInterface.cpp:

#include "OggVorbisStreamer.h"

MainWindow::MainWindow() : etc

   menuMusic = nullptr;
   if ((world) && (!multiplayer))
   {
      world->SetWorldFlags(world->GetWorldFlags() | kWorldPaused);
   }
   else
   {
      menuMusic = new Sound;
      OggVorbisStreamer *oggStreamer = new OggVorbisStreamer;
      oggStreamer->AddComponent("music name");
      menuMusic->SetSoundGroup(&TheGame->musicSoundGroup);
      menuMusic->Stream(oggStreamer);
      menuMusic->SetLoopCount(kSoundLoopInfinite);
      menuMusic->Play();

Be sure to include "Sound *menuMusic;" in "MGInterface.h".

Note: When specifying the name of the Ogg file, don't include the .ogg extension.

Playing Ogg music in the game's worlds

C4Sources.cpp:

#include "OggVorbisStreamer.h"

void Source::LoadSound(void)
{
///change this line:      WaveStreamer *streamer = new WaveStreamer;
         OggVorbisStreamer *streamer = new OggVorbisStreamer;

This will remove support for ADPCM WAV files for world's ambient sources (streaming background sound/music). Feel free to improve the code to support Ogg as well as ADPCM WAV files.

Note: The "sound" command only plays and displays WAV files - unless more code is edited.

Personal tools