#include <stdio.h>
#include <errno.h>
#include <math.h>
#include <signal.h>
#include <getopt.h>
#define PERIOD_NSEC (SPA_NSEC_PER_SEC/8)
struct port {
};
struct data {
struct port *port;
uint32_t clock_id;
int64_t offset;
uint64_t position;
};
{
struct data *data = userdata;
struct port *port = data->port;
uint64_t sample_offset, sample_period, sample_position, cycle;
if (data->clock_id != position->
clock.
id) {
data->clock_id = position->
clock.
id;
}
cycle = sample_position / sample_period;
if (sample_position % sample_period != 0)
++cycle;
sample_offset = cycle*sample_period - sample_position;
return;
return;
while (sample_offset < position->clock.duration) {
if (cycle % 2 == 0) {
uint8_t buf[] = { 0x90, 0x3c, 0x7f };
pw_log_info(
"note on at %"PRIu64, sample_position + sample_offset);
} else {
uint8_t buf[] = { 0x80, 0x3c, 0x7f };
pw_log_info(
"note off at %"PRIu64, sample_position + sample_offset);
}
sample_offset += sample_period;
++cycle;
}
}
{
struct data *data = userdata;
switch (state) {
data->offset = 0;
data->position = 0;
break;
default:
break;
}
}
.process = on_process,
};
static void do_quit(void *userdata, int signal_number)
{
struct data *data = userdata;
}
int main(int argc, char *argv[])
{
struct data data = {};
uint8_t buffer[1024];
"midi-src",
NULL),
&filter_events,
&data);
sizeof(struct port),
NULL),
NULL, 0);
NULL, 0) < 0) {
fprintf(stderr, "can't connect\n");
return -1;
}
return 0;
}
int pw_filter_connect(struct pw_filter *filter, enum pw_filter_flags flags, const struct spa_pod **params, uint32_t n_params)
Connect a filter for processing.
Definition filter.c:1548
int pw_filter_queue_buffer(void *port_data, struct pw_buffer *buffer)
Submit a buffer for playback or recycle a buffer for capture.
Definition filter.c:1994
pw_filter_state
The state of a filter
Definition filter.h:42
void * pw_filter_add_port(struct pw_filter *filter, enum pw_direction direction, enum pw_filter_port_flags flags, size_t port_data_size, struct pw_properties *props, const struct spa_pod **params, uint32_t n_params)
add a port to the filter, returns user data of port_data_size.
Definition filter.c:1780
#define PW_VERSION_FILTER_EVENTS
Definition filter.h:66
struct pw_buffer * pw_filter_dequeue_buffer(void *port_data)
Get a buffer that can be filled for output ports or consumed for input ports.
Definition filter.c:1976
int pw_filter_update_params(struct pw_filter *filter, void *port_data, const struct spa_pod **params, uint32_t n_params)
Update params, use NULL port_data for global filter params.
Definition filter.c:1892
void pw_filter_destroy(struct pw_filter *filter)
Destroy a filter
Definition filter.c:1385
struct pw_filter * pw_filter_new_simple(struct pw_loop *loop, const char *name, struct pw_properties *props, const struct pw_filter_events *events, void *data)
Definition filter.c:1281
@ PW_FILTER_FLAG_RT_PROCESS
call process from the realtime thread
Definition filter.h:108
@ PW_FILTER_PORT_FLAG_MAP_BUFFERS
mmap the buffers except DmaBuf that is not explicitly marked as mappable.
Definition filter.h:129
@ PW_FILTER_STATE_STREAMING
filter is streaming
Definition filter.h:47
#define PW_KEY_PORT_NAME
port name
Definition keys.h:335
#define PW_KEY_MEDIA_TYPE
Media.
Definition keys.h:497
#define PW_KEY_MEDIA_CATEGORY
Media Category: Playback, Capture, Duplex, Monitor, Manager.
Definition keys.h:500
#define PW_KEY_FORMAT_DSP
format related properties
Definition keys.h:540
#define PW_KEY_MEDIA_CLASS
class Ex: "Video/Source"
Definition keys.h:508
#define pw_log_trace(...)
Definition log.h:182
#define pw_log_info(...)
Definition log.h:180
#define pw_loop_add_signal(l,...)
Definition loop.h:68
int pw_main_loop_quit(struct pw_main_loop *loop)
Quit a main loop.
Definition main-loop.c:108
void pw_main_loop_destroy(struct pw_main_loop *loop)
Destroy a loop.
Definition main-loop.c:73
int pw_main_loop_run(struct pw_main_loop *loop)
Run a main loop.
Definition main-loop.c:122
struct pw_main_loop * pw_main_loop_new(const struct spa_dict *props)
Create a new main loop.
Definition main-loop.c:63
struct pw_loop * pw_main_loop_get_loop(struct pw_main_loop *loop)
Get the loop implementation.
Definition main-loop.c:96
void pw_init(int *argc, char **argv[])
Initialize PipeWire.
Definition pipewire.c:488
void pw_deinit(void)
Deinitialize PipeWire.
Definition pipewire.c:600
#define PW_DIRECTION_OUTPUT
Definition port.h:50
struct pw_properties * pw_properties_new(const char *key,...)
Make a new properties object.
Definition properties.c:96
@ SPA_CONTROL_Midi
data contains a spa_pod_bytes with raw midi data
Definition control.h:33
@ SPA_PARAM_Buffers
buffer configurations as SPA_TYPE_OBJECT_ParamBuffers
Definition param.h:35
@ SPA_PARAM_BUFFERS_size
size of a data block memory (Int)
Definition buffers.h:29
@ SPA_PARAM_BUFFERS_stride
stride of data block memory (Int)
Definition buffers.h:30
@ SPA_PARAM_BUFFERS_blocks
number of data blocks per buffer (Int)
Definition buffers.h:28
@ SPA_PARAM_BUFFERS_buffers
number of buffers (Int)
Definition buffers.h:27
#define SPA_POD_CHOICE_RANGE_Int(def, min, max)
Definition vararg.h:58
static int spa_pod_builder_push_sequence(struct spa_pod_builder *builder, struct spa_pod_frame *frame, uint32_t unit)
Definition builder.h:460
static void * spa_pod_builder_pop(struct spa_pod_builder *builder, struct spa_pod_frame *frame)
Definition builder.h:168
static int spa_pod_builder_control(struct spa_pod_builder *builder, uint32_t offset, uint32_t type)
Definition builder.h:471
#define spa_pod_builder_add_object(b, type, id,...)
Definition builder.h:659
static int spa_pod_builder_bytes(struct spa_pod_builder *builder, const void *bytes, uint32_t len)
Definition builder.h:315
static void spa_pod_builder_init(struct spa_pod_builder *builder, void *data, uint32_t size)
Definition builder.h:87
#define SPA_POD_Int(val)
Definition vararg.h:54
@ SPA_TYPE_OBJECT_ParamBuffers
Definition type.h:77
#define SPA_ID_INVALID
Definition defs.h:250
#define SPA_N_ELEMENTS(arr)
Definition defs.h:143
#define SPA_NSEC_PER_SEC
Definition defs.h:253
#define spa_assert(expr)
Definition defs.h:468
a buffer structure obtained from pw_stream_dequeue_buffer().
Definition stream.h:212
struct spa_buffer * buffer
the spa buffer
Definition stream.h:213
Events for a filter.
Definition filter.h:64
void(* state_changed)(void *data, enum pw_filter_state old, enum pw_filter_state state, const char *error)
when the filter state changes
Definition filter.h:71
struct spa_data * datas
array of data members
Definition buffer.h:104
uint32_t n_datas
number of data members
Definition buffer.h:102
int32_t stride
stride of valid data
Definition buffer.h:55
uint32_t size
size of valid data.
Definition buffer.h:53
int32_t flags
chunk flags
Definition buffer.h:64
uint32_t offset
offset of valid data.
Definition buffer.h:50
Data for a buffer this stays constant for a buffer.
Definition buffer.h:68
struct spa_chunk * chunk
valid chunk of memory
Definition buffer.h:96
void * data
optional data pointer
Definition buffer.h:95
uint32_t maxsize
max size of data
Definition buffer.h:94
uint32_t num
Definition defs.h:138
uint32_t denom
Definition defs.h:139
uint64_t position
Current position, in samples @ rate.
Definition io.h:155
struct spa_fraction rate
Rate for position/duration/delay/xrun.
Definition io.h:154
uint32_t id
Unique clock id, set by host application.
Definition io.h:147
uint64_t duration
Duration of current cycle, in samples @ rate.
Definition io.h:156
The position information adds extra meaning to the raw clock times.
Definition io.h:314
struct spa_io_clock clock
clock position of driver, always valid and read only
Definition io.h:315