Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
ultraq committed Feb 2, 2024
1 parent 9daec28 commit f9de8ce
Show file tree
Hide file tree
Showing 12 changed files with 322 additions and 91 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/*
/*
* Copyright 2007, Emanuel Rabina (http://www.ultraq.net.nz/)
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand All @@ -25,14 +25,14 @@ import java.nio.ByteBuffer
/**
* The audio renderer is responsible for setting up and playing back sounds
* through the audio device.
*
*
* @author Emanuel Rabina
*/
interface AudioRenderer {

/**
* Attaches a single buffer to a source.
*
*
* @param sourceId
* @param bufferId
*/
Expand All @@ -41,15 +41,15 @@ interface AudioRenderer {
/**
* Return the number of buffers that have been processed for the given source,
* which is the number of buffers that can be safely unqueued from the source.
*
*
* @param sourceId
* @return Number of processed buffers.
*/
int buffersProcessed(int sourceId)

/**
* Creates and fills a sound buffer with the given data.
*
*
* @param data
* @param bits
* @param channels
Expand All @@ -60,97 +60,97 @@ interface AudioRenderer {

/**
* Creates a new source through which to play sound data.
*
* @return Source ID.
*
* @return New source object.
*/
int createSource()
Source createSource()

/**
* Delete multiple buffers at once.
*
*
* @param bufferIds
*/
void deleteBuffers(int... bufferIds)
void deleteBuffers(int ... bufferIds)

/**
* Delete a source.
*
* @param sourceId
*
* @param source
*/
void deleteSource(int sourceId)
void deleteSource(Source source)

/**
* Pause playing a source.
*
*
* @param sourceId
*/
void pauseSource(int sourceId)

/**
* Start a source playing.
*
* @param sourceId
*
* @param source
*/
void playSource(int sourceId)
void playSource(Source source)

/**
* Queue some buffers to an existing source.
*
*
* @param sourceId
* @param bufferIds
*/
void queueBuffers(int sourceId, int... bufferId)
void queueBuffers(int sourceId, int ... bufferId)

/**
* Return whether a source with the given ID exists or not.
*
*
* @param sourceId
* @return
*/
boolean sourceExists(int sourceId)

/**
* Return whether a source is currently paused.
*
*
* @param sourceId
* @return
*/
boolean sourcePaused(int sourceId)

/**
* Return whether a source is currently playing.
*
*
* @param sourceId
* @return
*/
boolean sourcePlaying(int sourceId)

/**
* Return whether a source is currently stopped.
*
*
* @param sourceId
* @return
*/
boolean sourceStopped(int sourceId)

/**
* Stop playing a source.
*
*
* @param sourceId
*/
void stopSource(int sourceId)

/**
* Unqueue some buffers from an existing source.
*
*
* @param sourceId
* @param bufferIds
*/
void unqueueBuffers(int sourceId, int... bufferId)
void unqueueBuffers(int sourceId, int ... bufferId)

/**
* Update details about the listener.
*
*
* @param position
* @param velocity
* @param orientation
Expand All @@ -159,7 +159,7 @@ interface AudioRenderer {

/**
* Update details about the source.
*
*
* @param sourceId
* @param position
* @param direction
Expand All @@ -169,7 +169,7 @@ interface AudioRenderer {

/**
* Update the volume of the listener.
*
*
* @param volume
*/
void updateVolume(float volume)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright 2024, Emanuel Rabina (http://www.ultraq.net.nz/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package nz.net.ultraq.redhorizon.engine.audio

import java.util.concurrent.Future

/**
* Interface to make requests of the audio system.
*
* @author Emanuel Rabina
*/
interface AudioRequests {

static interface Request<T> {}

static record SourceRequest() implements Request<Source> {}

/**
* Request the creation or retrieval of the given resource type from the audio
* system, which will eventually be resolved in the returned {@code Future}.
*/
<V extends AudioResource, R extends Request<V>> Future<V> requestCreateOrGet(R request)

/**
* Request the audio system to delete a resource.
*/
void requestDelete(AudioResource... resources)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright 2024, Emanuel Rabina (http://www.ultraq.net.nz/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package nz.net.ultraq.redhorizon.engine.audio

/**
* Identifies a resource that can only be created/deleted via the audio system
* and its thread.
*
* @author Emanuel Rabina
*/
interface AudioResource extends Closeable {
}
Loading

0 comments on commit f9de8ce

Please sign in to comment.