UEFIStarter
a simple UEFI framework
Macros | Functions
ac97.c File Reference

AC'97 audio demo. More...

#include <Uefi.h>
#include <Library/UefiLib.h>
#include <Library/ShellCEntryLib.h>
#include <Library/UefiBootServicesTableLib.h>
#include <UEFIStarter/core.h>
#include <UEFIStarter/ac97.h>
#include <UEFIStarter/pci.h>

Macros

#define SAMPLES_PER_BUFFER   10000
 Number of samples to use in each buffer. More...
 
#define SAMPLES_FREQ(FREQ)   ((tc%(FREQ))*60000/(FREQ)-30000)
 Shortcut macro to sample a (non-harmonic) frequency. More...
 

Functions

void fill_buffers_crossscale (ac97_buffers_s16_t *buffers, unsigned int start_buffer, unsigned int buffer_count, unsigned int loop_offset)
 Fills audio buffers with scales, one channel going down, the other channel going up. More...
 
void fill_buffers_harmonic_scale (ac97_buffers_s16_t *buffers, unsigned int start_buffer, unsigned int buffer_count)
 Fills audio buffers with harmonic scales. More...
 
void output_audio (ac97_handle_t *handle)
 Fills audio buffers with scales, copies buffers to AC'97 device and starts playback. More...
 
void loop_civ (ac97_handle_t *handle)
 This fills audio buffers while they're being played. More...
 
EFI_STATUS run_audio_stuff (EFI_PCI_IO_PROTOCOL *audio)
 Handles entire lifetime of AC'97 audio output. More...
 
INTN EFIAPI ShellAppMain (UINTN argc, CHAR16 **argv)
 Main function, gets invoked by UEFI shell. More...
 

Detailed Description

AC'97 audio demo.

Author
Richard Nusser
License
GPLv3 (see http://www.gnu.org/licenses/)
See also
https://github.com/rinusser/UEFIStarter
Warning
This application accesses your audio hardware directly, take care about the sound volume in particular. A volume of 100% (the maximum) will set your master and PCM OUT volumes to 100%. If you're running this on hardware directly (because you e.g. booted a computer into this environment), this means the sound volume will be as high as it can possibly go (apart from vendor-specific additional volume boosts). Depending on your audio setup this may even cause damage to your amplifier, speakers or hearing: reduce any attached devices' (e.g. speakers') volumes before starting this application. If you're running this in a virtual environment, e.g. VirtualBox, this will output at 100% of the hypervisor's volume.

Macro Definition Documentation

◆ SAMPLES_PER_BUFFER

#define SAMPLES_PER_BUFFER   10000

Number of samples to use in each buffer.

Determines length of individual notes (thus speed of playback). Keep this value below 32767.

◆ SAMPLES_FREQ

#define SAMPLES_FREQ (   FREQ)    ((tc%(FREQ))*60000/(FREQ)-30000)

Shortcut macro to sample a (non-harmonic) frequency.

Parameters
FREQthe frequency to use (of no particular unit)
Returns
the generated sample

Function Documentation

◆ fill_buffers_crossscale()

void fill_buffers_crossscale ( ac97_buffers_s16_t buffers,
unsigned int  start_buffer,
unsigned int  buffer_count,
unsigned int  loop_offset 
)

Fills audio buffers with scales, one channel going down, the other channel going up.

Does not use the harmonic scale: this will sound bad.

Parameters
buffersthe AC'97 buffer list to fill
start_bufferindex of the first buffer to fill
buffer_countthe number of buffers to fill
loop_offsetoffset for loop counter, the higher this is the higher the generated notes will be

◆ fill_buffers_harmonic_scale()

void fill_buffers_harmonic_scale ( ac97_buffers_s16_t buffers,
unsigned int  start_buffer,
unsigned int  buffer_count 
)

Fills audio buffers with harmonic scales.

Parameters
buffersthe audio buffers to write to
start_bufferindex of the first buffer to fill
buffer_countnumber of buffers to fill

◆ output_audio()

void output_audio ( ac97_handle_t handle)

Fills audio buffers with scales, copies buffers to AC'97 device and starts playback.

This is pretty much how you'd output prepared audio, e.g. when playing music.

Start the application with -trace to see when playback switches to the next buffer.

Parameters
handlethe AC'97 handle to use

◆ loop_civ()

void loop_civ ( ac97_handle_t handle)

This fills audio buffers while they're being played.

This is how you'd output audio on the fly, e.g. sound effects that depend on user inputs.

Seems like the timer granularity can't be decreased much, setting it to e.g. 5ms loses count of a few ticks.

Parameters
handlethe AC'97 handle to use

◆ run_audio_stuff()

EFI_STATUS run_audio_stuff ( EFI_PCI_IO_PROTOCOL *  audio)

Handles entire lifetime of AC'97 audio output.

This shows the high-level interface to the AC'97 library: find the audio device, initialize the handle, configure audio output, fill buffers, start playback and finally close the handle.

Parameters
audiothe UEFI PCI I/O protocol for the AC'97 chipset
Returns
the resulting status, EFI_SUCCESS if everything went OK

◆ ShellAppMain()

INTN EFIAPI ShellAppMain ( UINTN  argc,
CHAR16 **  argv 
)

Main function, gets invoked by UEFI shell.

Parameters
argcthe number of command-line arguments passed
argvthe command-line arguments passed
Returns
an EFI status code for the shell