aboutsummaryrefslogtreecommitdiff
path: root/Minecraft.Client/PS3/Audio/PS3_SoundEngine.cpp
blob: 1c7edba306771b2a19d0b5680d875a69a52a2f34 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#include "..\stdafx.h"
#include <sysutil/sysutil_sysparam.h>
#include <cell/sysmodule.h>
#include <sys/spu_initialize.h>
#include <fcntl.h>
#include <unistd.h>
#include <cell/audio.h>
#include "..\..\Common\Audio\SoundEngine.h"
#include "..\..\Common\Consoles_App.h"
#include "..\..\PS3\Miles\include\mss.h"

// This file has the platform specific functions required for PS3 audio

//
// this function configures the audio hardware.
//   you specify the minimum number of channels that you need, and it 
//   returns the number of output channels that will be used (which will
//   be at least your minimum count, but possibly more).  it will return 0
//   for any failure cases.

int SoundEngine::initAudioHardware( int minimum_chans )
{
	int ret;
	int ch_pcm;
	int ch_bit;
	CellAudioOutConfiguration a_config;

	memset( &a_config, 0, sizeof( CellAudioOutConfiguration ) );

	// first lets see how many pcm output channels we have
	ch_pcm = cellAudioOutGetSoundAvailability( CELL_AUDIO_OUT_PRIMARY,
		CELL_AUDIO_OUT_CODING_TYPE_LPCM,
		CELL_AUDIO_OUT_FS_48KHZ, 0 );

	if ( ch_pcm >= minimum_chans )
	{
		a_config.channel = ch_pcm;
		a_config.encoder = CELL_AUDIO_OUT_CODING_TYPE_LPCM;
		a_config.downMixer = CELL_AUDIO_OUT_DOWNMIXER_NONE; /* No downmixer is used */
		cellAudioOutConfigure( CELL_AUDIO_OUT_PRIMARY, &a_config, nullptr, 0 );

		ret = ch_pcm;
	}
	else
	{
		switch ( ch_pcm )
		{
		case 6:
			// this means we asked for 8 channels, but only 6 are available
			//   so, we'll turn on the 7.1 to 5.1 downmixer.
			a_config.channel = 6; 
			a_config.encoder = CELL_AUDIO_OUT_CODING_TYPE_LPCM;
			a_config.downMixer = CELL_AUDIO_OUT_DOWNMIXER_TYPE_B; 
			if ( cellAudioOutConfigure( CELL_AUDIO_OUT_PRIMARY, &a_config, nullptr, 0 ) != CELL_OK )
			{
				return 0; // error - the downmixer didn't init
			}

			ret = 8;
			break;

		case 2:
			// ok, this means they asked for multi-channel out, but only stereo
			//   is supported.  we'll try dolby digital first and then the downmixer

			ch_bit = cellAudioOutGetSoundAvailability( CELL_AUDIO_OUT_PRIMARY,
				CELL_AUDIO_OUT_CODING_TYPE_AC3,
				CELL_AUDIO_OUT_FS_48KHZ, 0 );
			if ( ch_bit > 0 ) 
			{
				a_config.channel = ch_bit;
				a_config.encoder = CELL_AUDIO_OUT_CODING_TYPE_AC3;
				if ( ch_bit >= minimum_chans )
				{
					// we have enough channels to support their minimum
					a_config.downMixer = CELL_AUDIO_OUT_DOWNMIXER_NONE;
					ret = ch_bit;
				}
				else
				{
					// we don't have enough channels to support their minimum, so use the downmixer
					a_config.downMixer = CELL_AUDIO_OUT_DOWNMIXER_TYPE_B;
					ret = 8;
				}

				if ( cellAudioOutConfigure( CELL_AUDIO_OUT_PRIMARY, &a_config, nullptr, 0 ) == CELL_OK )
				{
					break;
				}

				// if we got here the dolby encoder, didn't init, so fall through to downmixing to stereo
			}

			a_config.channel = 2;
			a_config.encoder   = CELL_AUDIO_OUT_CODING_TYPE_LPCM;
			a_config.downMixer = CELL_AUDIO_OUT_DOWNMIXER_TYPE_A;
			if ( cellAudioOutConfigure( CELL_AUDIO_OUT_PRIMARY, &a_config, nullptr, 0 ) != CELL_OK )
			{
				return 0; // error - downmixer didn't work
			}

			ret = 2; // downmixer does 7.0 to 2.0 downmixing...
			break;

		default:
			// some other weird case that we don't understand
			return 0;
		}
	}

	// turn off copy protection stupidness
	cellAudioOutSetCopyControl( CELL_AUDIO_OUT_PRIMARY,
		CELL_AUDIO_OUT_COPY_CONTROL_COPY_FREE );

	return( ret );
}