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