Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added kinc_player/Deployment/files/alphavil.mod
Binary file not shown.
Binary file not shown.
Binary file added kinc_player/Deployment/files/chop1.wav
Binary file not shown.
11 changes: 11 additions & 0 deletions kinc_player/Deployment/g1.frag
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#version 110

uniform sampler2D tex;

varying vec2 texCoord;

void main()
{
gl_FragData[0] = texture2D(tex, texCoord);
}

12 changes: 12 additions & 0 deletions kinc_player/Deployment/g1.vert
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#version 110

attribute vec3 pos;
varying vec2 texCoord;
attribute vec2 tex;

void main()
{
gl_Position = vec4(pos.x, pos.y, 0.5, 1.0);
texCoord = tex;
}

9 changes: 9 additions & 0 deletions kinc_player/Deployment/painter-colored.frag
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#version 110

varying vec4 fragmentColor;

void main()
{
gl_FragData[0] = fragmentColor;
}

14 changes: 14 additions & 0 deletions kinc_player/Deployment/painter-colored.vert
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#version 110

uniform mat4 projectionMatrix;

attribute vec3 vertexPosition;
varying vec4 fragmentColor;
attribute vec4 vertexColor;

void main()
{
gl_Position = projectionMatrix * vec4(vertexPosition, 1.0);
fragmentColor = vertexColor;
}

15 changes: 15 additions & 0 deletions kinc_player/Deployment/painter-image.frag
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#version 110

uniform sampler2D tex;

varying vec2 texCoord;
varying vec4 color;

void main()
{
vec4 texcolor = texture2D(tex, texCoord) * color;
vec3 _32 = texcolor.xyz * color.w;
texcolor = vec4(_32.x, _32.y, _32.z, texcolor.w);
gl_FragData[0] = texcolor;
}

17 changes: 17 additions & 0 deletions kinc_player/Deployment/painter-image.vert
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#version 110

uniform mat4 projectionMatrix;

attribute vec3 vertexPosition;
varying vec2 texCoord;
attribute vec2 vertexUV;
varying vec4 color;
attribute vec4 vertexColor;

void main()
{
gl_Position = projectionMatrix * vec4(vertexPosition, 1.0);
texCoord = vertexUV;
color = vertexColor;
}

12 changes: 12 additions & 0 deletions kinc_player/Deployment/painter-text.frag
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#version 110

uniform sampler2D tex;

varying vec4 fragmentColor;
varying vec2 texCoord;

void main()
{
gl_FragData[0] = vec4(fragmentColor.xyz, texture2D(tex, texCoord).x * fragmentColor.w);
}

17 changes: 17 additions & 0 deletions kinc_player/Deployment/painter-text.vert
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#version 110

uniform mat4 projectionMatrix;

attribute vec3 vertexPosition;
varying vec2 texCoord;
attribute vec2 vertexUV;
varying vec4 fragmentColor;
attribute vec4 vertexColor;

void main()
{
gl_Position = projectionMatrix * vec4(vertexPosition, 1.0);
texCoord = vertexUV;
fragmentColor = vertexColor;
}

15 changes: 15 additions & 0 deletions kinc_player/Deployment/painter-video.frag
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#version 110

uniform sampler2D tex;

varying vec2 texCoord;
varying vec4 color;

void main()
{
vec4 texcolor = texture2D(tex, texCoord) * color;
vec3 _32 = texcolor.xyz * color.w;
texcolor = vec4(_32.x, _32.y, _32.z, texcolor.w);
gl_FragData[0] = texcolor;
}

17 changes: 17 additions & 0 deletions kinc_player/Deployment/painter-video.vert
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#version 110

uniform mat4 projectionMatrix;

attribute vec3 vertexPosition;
varying vec2 texCoord;
attribute vec2 vertexUV;
varying vec4 color;
attribute vec4 vertexColor;

void main()
{
gl_Position = projectionMatrix * vec4(vertexPosition, 1.0);
texCoord = vertexUV;
color = vertexColor;
}

20 changes: 20 additions & 0 deletions kinc_player/kfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
let project = new Project('hxcmodplayer_kinc');

project.cpp = false;
project.cStd = "c99"

await project.addProject('PATH TO/Kinc');

// -- comment out if you don't want visual output for player
project.addDefine('USE_TRACKBUFFER')
project.addFile('../framegenerator.c');
project.addFile('../packer/*.c');
// ---------------------------------------------------------
project.addFile('src/*.c');
project.addFile('../hxcmod.c');

project.setDebugDir('Deployment');

project.flatten();

resolve(project);
41 changes: 41 additions & 0 deletions kinc_player/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
* kinc ( https://github.com/Kode/Kinc )-backend by dertom

* to build the player:
* kfile-js: modify 'kinc'-path to point to your kinc-installation
* in the kfile you can deactivate visual output
* run 'kmake' in kinc_player-folder and build with your systems build-tool
* copy exe in Deployment folder and run exe
* space: toggle (un)pause
* 1 : play song 1
* 2 : play song 2
* 3 : play a short wav-sound (to test A1 and MOD-mixing)
* esc: stop

To use the api you only need kinc_hxcmod.h/c and hxcmode.h/.c.

```
void kinc_mod_init(void); // init the api( inits kinc_a1 and kinc_a2)

/// play mod from file, memory of loaded file automatically released on stop-/play-call
bool kinc_mod_play(const char* filename);
/// play mod from memory, user needs to release this data on his own
void kinc_mod_play_from_memory(void* data,size_t size);

void kinc_mod_stop(void);
void kinc_mod_pause(void);
void kinc_mod_unpause(void);

bool kinc_mod_is_stopped(void);
bool kinc_mod_is_paused(void);
bool kinc_mod_is_playing(void);

void kinc_mod_shutdown(void);

// give the whole a1-mix a 'volume' and the mod-sound a volume for mixing them together
void kinc_mod_a1_mod_mixing(float a1_volume,float mod_volume);


#ifdef USE_TRACKBUFFER
tracker_buffer_state* kinc_mod_trackbufferstate();
#endif
```
167 changes: 167 additions & 0 deletions kinc_player/src/kinc_hxcmod.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
#include "kinc_hxcmod.h"
#include "../../hxcmod.h"
#include <kinc/audio1/audio.h>
#include <kinc/audio2/audio.h>

#include <kinc/io/filereader.h>
#include <kinc/log.h>
#include <kinc/memory.h>
#include <kinc/system.h>
#include <kinc/math/core.h>
#include <string.h>

modcontext modloaded;
float a1_volume = 1.0f;
float mod_volume = 1.0f;

bool current_file_data_locked = false;
uint8_t* current_file_data=0;

int16_t output_samples[SAMPLERATE];
#ifdef USE_TRACKBUFFER
tracker_buffer_state trackbuf_state1;
#endif

typedef enum { KINC_MOD_STOPPED,KINC_MOD_RUNNING,KINC_MOD_PAUSED } kinc_mod_state_t;
kinc_mod_state_t mod_state = KINC_MOD_STOPPED;

static void mixaudio_callback(kinc_a2_buffer_t *buffer, int samples){
int write_location = buffer->write_location;

// call a1 to do its mixing
kinc_a1_mix(buffer,samples);
// go back to the position and mix the mod into the A1-mix
buffer->write_location = write_location;

if (mod_state==KINC_MOD_PAUSED || mod_state==KINC_MOD_STOPPED){
// nothing to play
for (int idx=0;idx<samples;idx++){
*((float*)&(buffer->data[buffer->write_location]))=0;
buffer->write_location+=4;
if (buffer->write_location>=buffer->data_size){
buffer->write_location=0;
}
}
return;
}

#ifdef USE_TRACKBUFFER
trackbuf_state1.nb_of_state = 0;
hxcmod_fillbuffer(&modloaded, &output_samples[0], samples/2, &trackbuf_state1);
#else
hxcmod_fillbuffer(&modloaded, &output_samples[0], samples/2, 0);
#endif

for (int idx=0;idx<samples;idx++){
//float new_mix_value=output_samples[idx] / 32767.0f;
float new_mix_value = (*((float*)&(buffer->data[buffer->write_location]))*a1_volume + output_samples[idx] / 32767.0f)*mod_volume;
//*((float*)&(buffer->data[buffer->write_location]))=kinc_clamp(new_mix_value,-1.0f,1.0f);
*((float*)&(buffer->data[buffer->write_location]))=new_mix_value;
buffer->write_location+=4;
if (buffer->write_location>=buffer->data_size){
buffer->write_location=0;
}
}
}

void kinc_mod_init()
{
kinc_a1_init();
kinc_a2_init();
kinc_a2_set_callback(mixaudio_callback);
hxcmod_init(&modloaded);
hxcmod_setcfg(&modloaded, SAMPLERATE, 0, 0);
}

void kinc_mod_shutdown(void)
{
kinc_mod_stop();
kinc_a2_shutdown();
}

bool kinc_mod_play(const char* filename)
{
kinc_mod_stop();
kinc_file_reader_t file;
if (!kinc_file_reader_open(&file,filename,KINC_FILE_TYPE_ASSET)){
kinc_log(KINC_LOG_LEVEL_ERROR,"Could not open mod-file:%s",filename);
return false;
}
size_t file_size = kinc_file_reader_size(&file);
current_file_data = kinc_allocate(file_size);
current_file_data_locked = true; // lock the data, so it won't be disposed by kinc_mod_play_from_memory
kinc_file_reader_read(&file,current_file_data,file_size);
kinc_file_reader_close(&file);
kinc_mod_play_from_memory((void*)current_file_data,file_size);
return true;
}

void kinc_mod_play_from_memory(void* mod_data,size_t mod_size){
if (!current_file_data_locked && current_file_data) {
kinc_free(current_file_data);
current_file_data = 0;
}
current_file_data_locked = false;
hxcmod_unload(&modloaded);
hxcmod_load(&modloaded,(void*)mod_data,mod_size);
mod_state = KINC_MOD_RUNNING;
#ifdef USE_TRACKBUFFER
memset(&trackbuf_state1,0,sizeof(tracker_buffer_state));

trackbuf_state1.nb_max_of_state = 100;
trackbuf_state1.track_state_buf = malloc(sizeof(tracker_state) * trackbuf_state1.nb_max_of_state);
memset(trackbuf_state1.track_state_buf,0,sizeof(tracker_state) * trackbuf_state1.nb_max_of_state);
trackbuf_state1.sample_step = ( NBSTEREO16BITSAMPLES ) / trackbuf_state1.nb_max_of_state;
#endif
}

void kinc_mod_pause(void)
{
mod_state=KINC_MOD_PAUSED;
}

void kinc_mod_unpause(void)
{
if (kinc_mod_is_paused()){
mod_state=KINC_MOD_RUNNING;
}
}

void kinc_mod_stop(void)
{
if (current_file_data){
kinc_free(current_file_data);
current_file_data=NULL;
}
hxcmod_unload(&modloaded);
}

#ifdef USE_TRACKBUFFER
tracker_buffer_state* kinc_mod_trackbufferstate()
{
return &trackbuf_state1;
}
#endif

bool kinc_mod_is_playing(void)
{
return mod_state==KINC_MOD_RUNNING;
}

bool kinc_mod_is_stopped(void)
{
return mod_state==KINC_MOD_STOPPED;
}

bool kinc_mod_is_paused(void
)
{
return mod_state==KINC_MOD_PAUSED;
}

void kinc_mod_a1_mod_mixing(float _a1_volume,float _mod_volume)
{
a1_volume = kinc_clamp(_a1_volume,0.0f,10.0f);
mod_volume = kinc_clamp(_mod_volume,0.0f,10.0f);
}

Loading