• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: GPL-2.0
2 //
3 // frame-cache.h - maintainer of cache for data frame.
4 //
5 // Copyright (c) 2018 Takashi Sakamoto <o-takashi@sakamocchi.jp>
6 //
7 // Licensed under the terms of the GNU General Public License, version 2.
8 
9 #include <alsa/asoundlib.h>
10 
11 struct frame_cache {
12 	void *buf;
13 	void *buf_ptr;
14 
15 	unsigned int remained_count;
16 
17 	snd_pcm_access_t access;
18 	unsigned int bytes_per_sample;
19 	unsigned int samples_per_frame;
20 	unsigned int frames_per_cache;
21 
22 	void (*align_frames)(struct frame_cache *cache,
23 			     unsigned int consumed_count);
24 };
25 
26 int frame_cache_init(struct frame_cache *cache, snd_pcm_access_t access,
27 		     unsigned int bytes_per_sample,
28 		     unsigned int samples_per_frame,
29 		     unsigned int frames_per_cache);
30 void frame_cache_destroy(struct frame_cache *cache);
31 
frame_cache_get_count(struct frame_cache * cache)32 static inline unsigned int frame_cache_get_count(struct frame_cache *cache)
33 {
34 	return cache->remained_count;
35 }
36 
frame_cache_increase_count(struct frame_cache * cache,unsigned int frame_count)37 static inline void frame_cache_increase_count(struct frame_cache *cache,
38 					      unsigned int frame_count)
39 {
40 	cache->remained_count += frame_count;
41 }
42 
frame_cache_reduce(struct frame_cache * cache,unsigned int consumed_count)43 static inline void frame_cache_reduce(struct frame_cache *cache,
44 				      unsigned int consumed_count)
45 {
46 	cache->align_frames(cache, consumed_count);
47 }
48